inblog logo
|
p4rksk
    JavaScript

    JavaScript - JQuery(Hide, Show, 시간 설정)

    박선규's avatar
    박선규
    Feb 22, 2024
    JavaScript - JQuery(Hide, Show, 시간 설정)
    Contents
    Hide/Show사라지는 시간 설정
     

    Hide/Show

    <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> </head> <body> <p>If you click on the "Hide" button, I will disappear.</p> <button id="hide">Hide</button> <button id="show">Show</button> <script> $(document).ready(function () { $("#hide").click(function () { $("p").hide();//숨기기 }); $("#show").click(function () { $("p").show();//보이기 }); }); </script>

    Hide를 눌렀을 때

    notion image

    Show를 눌렀을 때

    notion image
     

    사라지는 시간 설정

    <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> </head> <body> <button>Hide</button> <p>This is a paragraph with little content.</p> <p>This is another small paragraph.</p> <script> $(document).ready(function () { $("button").click(function () { $("p").hide(1000); //1초 동안 천천히 숨기기 }); }); </script> </body> </html>

    화면 접속했을 때

    notion image

    1초 동안 천천히 숨겨진다.

    notion image
     

    togle(보이고 사라지고 동시 설정)

    <!DOCTYPE html> <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script> </head> <body> <button>Toggle between hiding and showing the paragraphs</button> <p>This is a paragraph with little content.</p> <p>This is another small paragraph.</p> <script> $(document).ready(function () { $("button").click(function () { $("p").toggle(); // toggle은 숨기고 보이고를 동시에 설정 가능함 }); }); </script> </body> </html>

    초기 화면

    notion image
     

    처음 버튼을 눌렀을 때 사라짐

    notion image
     

    두번째 버튼을 눌렀을 때 다시 보임

    notion image
    Share article

    p4rksk

    RSS·Powered by Inblog