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