javascript - execute jquery code when user scrolls down a certain amount (pixels) -


i execute below code when user scrolls position on page; instance 600px; down (from top). detect 600px down in pixels.

// $(document).ready(function() {         $(".slidedown").one('load', function () {             $(this).slidedown(200);         }).each(function() {           if(this.complete) $(this).trigger('load');         }); // }); 

this did not work:

  $(document).scroll(function(){       if (document.scrollheight > 600) {      $(".slidedown").one('load', function () {         $(this).slidedown(200);     }).each(function() {       if(this.complete) $(this).trigger('load');     });    } }); 

simply set threshold of # of pixels before fire event , function triggered when user scrolls or down n pixels

https://jsfiddle.net/7daffjh8/7/

var scrollamount = 0; var pixelstonotify = 200;  $(document).scroll(function() {   var distance = $(window).scrolltop();     console.log(distance, scrollamount);     if(distance - scrollamount > pixelstonotify){         alert('user scrolled down event');         scrollamount = distance;     }     if(distance < scrollamount - pixelstonotify){         alert('user scrolled event');         scrollamount = distance;     } }); 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -