상세 컨텐츠

본문 제목

[j쿼리] slideup slidedown

카테고리 없음

by esoesmio 2023. 5. 25. 20:30

본문

<!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>

</body>

<script>
    $("#hide").on("click", () => {
        // $(".box").hide();
        $(".box").slideUp(1000, () => {
            alert("숨김완료")
        })
    });
    $("#show").on("click", () => {
        // $(".box").show();
        $(".box").slideDown(1000, () => {
            alert("쇼우완료")
        })
    });
    let interval;
    $("#toggle").on("click", () => {
        //박스 1초마다 숨김/표출 반복
        ///숨겨졌을 때는 숨김완료
        ////나타났을 때는 표출완료
        interval = setInterval(() => {
            $(".box").slideToggle(() => {
                if ($(".box").css("display") === 'none') {
                    alert("이건하이드")
                } else {
                    console.log($(".box").display);
                    alert('이건쇼우')
                }


            })
        }, 1000)


    });
    $("#fadeto").on("click",()=>{
        $(".box").fadeTo(1000,0.3,()=>{
            alert("투명도 30% 적용");
        })

    })

</script>
</html>

댓글 영역