2014-12-24 2 views
1

페이지가로드 된 후 2 초 후에 $(document).scrollTop()을 확인하고 싶습니다. 어떻게해야합니까? 누군가 나를 도울 수 있습니까? jQuery에서 초보자입니까? 몇 초 후에 문서의 scrollTop()을 확인하십시오.

나는이 시도했지만 작동하지 않습니다 :

$(document).delay(2000).scrollTop() 
+6

'setTimeout'은 당신의 악마입니다. – undefined

+0

지연 대신'setTimeout'을 사용하십시오. – Parody

+1

['.delay()'] (http://api.jquery.com/delay/)는 jQuery에서 대기중인 효과에만 사용할 수 있습니다. 그것은'setTimeout()'을 대체하기위한 것이 아닙니다. – Terry

답변

9

document.ready가 트리거 된 후에는 setTimeout() 기능을 사용하여 수행 할 수 있습니다

$(function(){ //wait for document ready 

    setTimeout(function(){ 
    $(document).scrollTop() 
    }, 2000) //execute your function after 2 seconds. 

}); 
0

첫 번째 단계는 이벤트를 발생하는 것입니다 처리기를로드합니다. 이 이벤트는 문서 준비 이벤트입니다.

두 번째 단계는 지정된 지연 후에 필요한 기능을 실행할 시간 초과를 만드는 것입니다.

var scrollTimeout = null; 
var jDocument = $(document); 
jDocument.ready(function() { //An event fired when the document finishes loading. 
    scrollTimeout = setTimeout(function() { //A function the will be executed after 2000ms 
     jDocument.scrollTop(); //your code goes here. 
    }, 2000); 
}); 
관련 문제