상세 컨텐츠

본문 제목

[j쿼리] 페이드인 페이드투

카테고리 없음

by esoesmio 2023. 5. 24. 17:38

본문

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Title</title>
    <script src="https://code.jquery.com/jquery-3.7.0.min.js"></script>

    <style>
        .box {
            width: 100px;
            height: 100px;
            background-color: blue;

        }
    </style>
</head>
<body>
<div class="box"></div>
<button id="hide" type="button">하이드</button>
<button id="show" type="button">쇼우</button>
<button id="toggle" type="button">toggle</button>
<button id="fadeto" type="button">fadeto</button>
<p></p>

</body>

<script>
$("#hide").on("click",()=>{
    $(".box").fadeOut(1000,()=>{
   document.querySelector("p").textContent = '페이드아웃됨'
    })
});
$("#show").on("click",()=>{
    $(".box").fadeIn(1000,()=>{
        document.querySelector("p").textContent = "페이드인됨"
    })
});
$("#toggle").on("click",()=>{

    $(".box").fadeToggle(1000,()=>{
        if($(".box").css('display')=='none'){
            document.querySelector("p").textContent = '토글 페이드아웃'
        }else{
            document.querySelector("p").textContent = '토글 페이드인'
        }

    })
});
$("#fadeto").on("click",()=>{
    $(".box").fadeTo(1000,0.3,()=>{

        document.querySelector("p").textContent = '투명도 적용됨'
    })
})






</script>
</html>

댓글 영역