So, I would like to run the function only once on the scroll (using the Scrollstop specified by stackoverflow answer)
The problem is that I do not run the function only once. I tried different solutions (.on (), setting the counter, setting it outside / inside the window.scrollstop function), but nothing worked.
I donโt think itโs difficult, but .. I couldnโt get it to work so far.
Here is the plugin that I use
$.fn.scrollStopped = function(callback) { $(this).scroll(function(){ var self = this, $this = $(self); if ($this.data('scrollTimeout')) { clearTimeout($this.data('scrollTimeout')); } $this.data('scrollTimeout', setTimeout(callback,300,self)); }); };
and here is my code:
$(window).scrollStopped(function(){ if ($(".drawing1").withinViewport()) { doNothing() } }) var doNothing = function() { $('#drawing1').lazylinepainter('paint'); }
(deleted the counter since it did not work)
Live demo here
PS: the function that I would like to do only once is lazyPaint. It starts when we go to the element, but it fires again when it ends.
Naemy source share