본문 바로가기

HTML/Javascript 기초

[Javascript] 애니메이션 사용하기(fadeIn, fadeOut)

애니메이션을 이용하여 fadein fadeout 효과를 줄 수 있다.

fadeIn(duration, ease function) 서서히 나타남

fadeOut(duration, ease function) 서서히 사라짐

 

<!DOCTYPE html>
<html lang="ko">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>easing fadein fadeout</title>
    <script src="../../js/jquery-3.5.1.min.js"></script>
    <script src="../../js/jquery.easing.1.3.js"></script>
    <script>
        $(document).ready(function () {
            $("#fadein").click(function(){
                $("#target").fadeIn(6000,"easeInQuint" ,function(){
                    alert("show complete");
                });
            });

            $("#fadeout").click(function(){
                $("#target").fadeOut(6000,"easeOutQuint" ,function(){
                    alert("hide complete");
                });
            });
        });
    </script>
</head>

<body>
    <div>
        <button id="fadein">show</button> &nbsp;
        <button id="fadeout">hide</button>
    </div>
    <br><br>
    <div id="target" style="display: none;">
    <img src="../../images/1.png">
</div>
</body>

</html>

 

728x90
반응형