[질문 :
모범에 링크 :http://jsfiddle.net/j65yQ/".scrollTop()"메서드의 결과 값은 무엇입니까? - jQuery를, HTML
/* First: */
/* Set the Position of the Division Tag to Fixed When Reaching the Top of the Window While Scrolling */
$(window).scroll(function(){
var u_div_cn = $('div#container_nav');
var u_os_top_read = $('div#container_nav').offset().top;
if ($(window).scrollTop() > u_os_top_read) {
u_div_cn.addClass('set_position');};
});
resulting value
가 스크롤 할 때 얻을 .scrollTop()
합니까?
위의 예에서 division tag
은 window
의 맨 위에 도달했을 때 conditional if statement
에 의해 고정되도록 position 속성을 설정합니다.
하지만, 왜이 예에서와 는.offset().top
일 "이상은"달리 "에 해당하는"많은 시도 후 작동하지zero
? 예를 들어
은은 "같음"을 위해 : 나는 window
의 top: 0
에서뿐만 아니라 잘 작동하도록 equals to
생각하기 때문에 내가 부탁하고 왜
$(window).scroll(function(){
var u_div_cn = $('div#container_nav');
var u_div_cn_os_top = $('div#container_nav').scrollTop();
if (u_div_cn_os_top == 0) {
u_div_cn.addClass('set_position');
};
});
이유이다.
답변 해 주셔서 감사합니다. 이것은 내가 찾고 있었던 바로 그 것이다. 이것은 '애니메이션'에만 해당되는가요? – user1860822
@ user1860822 : 아니요, 애니메이션과 관련이 없습니다. – Guffa