문제

how can i prevent this to be executed twice when i get to the bottom of the scroll?

 if  ($(window).scrollTop() == $(document).height() - $(window).height()){
                   last_msg_funtion();
 }

Options i see:

I tried setting a var loading_already == false and, something like:

if(loading_already==false){
     loading_already = true;
     last_msg_function();
     setTimeout('refresh_loading',300);
}

where

function refresh_loading(){ loading_already = false; }

But didn't work out, any suggestion for this?

thanks!

도움이 되었습니까?

해결책

loading_already = true;

You have == which is boolean is operator, not assignment.

다른 팁

You should use the awesome jQuery throttle/debounce plugin. Makes this sort of thing very easy.

The following example will ensure that las_msg_function is called no more than once every 250 milliseconds (assuming your scroll detection expression is correct);

if ($(window).scrollTop() == $(document).height() - $(window).height()) {
  $.throttle(250, las_msg_function);
}

Here's an example page which shows how this is used in conjunction with scroll detection (look at second example)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top