jQuery 수업

jQuery-6(이벤트 fadeIn(), fadeOut(), fadeTo(), fadeToggle())

줄라이퍼스트 2020. 2. 19. 11:30

※ fadeIn(), fadeOut(), fadeTo(), fadeToggle() 예제

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <script>
        $(document).ready(function(){

            // fadeIn
            $("#btn1").click(function(){
                $("#div1").fadeIn();
                $("#div2").fadeIn("slow");
                $("#div3").fadeIn(3000);
            });       

            // fadeOut
            $("#btn2").click(function(){
                $("#div1").fadeOut();
                $("#div2").fadeOut("slow");
                $("#div3").fadeOut(3000);
            });

            // fadeToggle
            $("#btn3").click(function(){
                $("#div1").fadeToggle();
                $("#div2").fadeToggle("slow");
                $("#div3").fadeToggle(3000);
            });

            // fadeTo
            $("#btn4").click(function(){
                // fadeTo(speed,opacity,callbakc)
                // fadeTo("slow",0.15);
                $("#div1").fadeTo("slow",0.15);
                $("#div2").fadeTo("slow",0.4);
                $("#div3").fadeTo("slow",0.7);
            });

        });
    </script>
</head>
<body>    
    <p>Demonstrate fadeIn() with different parameters.</p>

    <button id="btn1">Click to fade in boxes</button><br><br>
    <button id="btn2">Click to fade out boxes</button><br><br>
    <button id="btn3">Click to fade toggle boxes</button><br><br>
    <button id="btn4">Click to fade fadeto boxes</button><br><br>

    <div id="div1" style="width:80px;height:80px;display:none;background-color:red;"></div><br>
    <div id="div2" style="width:80px;height:80px;display:none;background-color:green;"></div><br>
    <div id="div3" style="width:80px;height:80px;display:none;background-color:blue;"></div>
    

</body>
</html>

 

※ fadeIn(), fadeOut() 버튼 눌렀을 때

 

fadeIn, Out 실행화면 - 클릭하시면 자세히 볼 수 있습니다.

 

 

※ fadeTo(), fadeToggle() 버튼 눌렀을 때

fadeTo, Toggle 실행화면 - 클릭하시면 자세히 볼 수 있습니다.