I am using a modified version of http://nick-jonas.imtqy.com/windows/ , which allows the user to scroll inside div sections, which will then be inserted into place.
As I scroll through the DIV, I replaced:
$('.windows').animate({scrollTop: scrollTo }, options.snapSpeed, function(){ if(!completeCalled){ if(t){clearTimeout(t);} t = null; completeCalled = true; options.onSnapComplete($visibleWindow); } });
from:
$('.windows').scrollTo( $visibleWindow , options.snapSpeed, { onAfter:function(){ if(!completeCalled){ if(t){clearTimeout(t);} t = null; completeCalled = true; options.onSnapComplete($visibleWindow); } }});
So, as you can see, I use the scrollTo plugin to go to the visible div, rather than relying on complex offsets like the previous code.
The error that I noticed in BOTH, the source code and my own is that if the binding started and then the user intercepts it by scrolling, they will fight the scrolling case to scroll through the contents. Therefore, if scrollTo scrolls 100 pixels, and then they scroll 300 pixels using the browser scroll bar, the screen will act as an event and combat the browser scroll.
Any ideas on how I can stop this? I hope that now I am using the scrollTo plugin, this will be easier to handle.
So far I have tried:
$('.windows').bind("scroll mousedown DOMMouseScroll mousewheel keyup", function(e){ if ( e.which > 0 || e.type === "mousedown" || e.type === "mousewheel"){ $(this).stop().unbind('scroll mousedown DOMMouseScroll mousewheel keyup'); } });
But that stops the binding at all ... any ideas for a fix?
javascript jquery scrollto
Cameron
source share