Question

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!

Was it helpful?

Solution

loading_already = true;

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

OTHER TIPS

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)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top