Recent Posts
Link
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
관리 메뉴

공부하자

제이쿼리(J-Query) 이벤트 메소드 scroll(), scrollTop() 본문

J-Query·JavaS

제이쿼리(J-Query) 이벤트 메소드 scroll(), scrollTop()

bluemoon527 2021. 1. 8. 21:14

제이쿼리 scroll() 이벤트 메소드 

: 선택한 요소에서 스크롤을 위,아래로 이동시켰을 때 발생하는 이벤트 메소드

 

 

 

문법

$("selector").scroll(function(){

  //  code

});

 

 

 

ex.

$(function(){

  $(window).scroll(function(){    //  윈도우(화면)이 스크롤 됐을 때

    if($(this).scrollTop() == 0){    //  만약 위치가 0 이라면

      $(".btn_top").hide(300);    //  300(0.3초)의 속도로 selector를 숨겨라

      }else{    // 조건과 맞지 않을 때

      $(".btn_top").show(300); //   나타냄

    }

  });

});

 

 

 

 

 

제이쿼리 scrollTop() 이벤트 메소드

:선택한 요소의 수직 위치를 알아내거나 특정값으로 이동시키는 이벤트 메소드

 

 

 

문법

$("selector").scrollTop(function(){

  //  code

});

 

 

 

ex.

$(function(){

  $(".btn_top").click(function(){    //  selector 를 클릭했을 때

      $("html").animate({

      "scrollTop":0    //  top:0의 위치로 이동해라

    }, 1000);    //  이동 속도

  });

});

 

 

 

 

 

api.jquery.com/scroll/#scroll-handler

 

.scroll() | jQuery API Documentation

Description: Bind an event handler to the "scroll" JavaScript event, or trigger that event on an element. This method is a shortcut for .on( "scroll", handler ) in the first and second variations, and .trigger( "scroll" ) in the third. The scroll event is

api.jquery.com

 

 

 

 

 

test.

ryu8811.github.io/jungle/class_4/07_scroll.html

 

Comments