javascript - jQuery Scrolling Length -
i working script scroll element on click. it's working properly, either scrolls way up, or way down. i'm new jquery, , i'm wondering how make scroll little @ at time. example, clicking scroll down once take down length, clicking again scrolls length again. also, jitters , bugs out when scrolling up. insight on how fix appreciated well!
thanks.
code below:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script> <script> $(function() { var ele = $('#scroll'); var speed = 25, scroll = 5, scrolling; $('#scroll-up').click(function() { // scroll element scrolling = window.setinterval(function() { ele.scrolltop( ele.scrolltop() - scroll ); }, speed); }); $('#scroll-down').click(function() { // scroll element down scrolling = window.setinterval(function() { ele.scrolltop( ele.scrolltop() + scroll ); }, speed); }); $('#scroll-up, #scroll-down').bind({ click: function(e) { // prevent default click action e.preventdefault(); }, mouseleave: function() { if (scrolling) { window.clearinterval(scrolling); scrolling = false; } } }); }); </script>
you're saying want scroll little @ time code saying scroll until mouse leaves. if want scroll little @ time why write mouseleave
stating if it's been scrolling stop now!
if want scroll up/down bit on click, should rid of setinterval
, mouseleave
.
$(function() { var ele = $('#scroll'); var speed = 25, scroll = 5; $('#scroll-up').click(function() { // scroll element ele.scrolltop( ele.scrolltop() - scroll ); }); $('#scroll-down').click(function() { ele.scrolltop( ele.scrolltop() + scroll ); }); $('#scroll-up, #scroll-down').bind({ click: function(e) { // prevent default click action e.preventdefault(); } }); });
Comments
Post a Comment