jquery - How does scrollTop() work -


i trying out how scroll or down table , snippet worked

$('.scroll-down').click(function() {      $('.tableholder').animate({         scrolltop: $('.tableholder').scrolltop() + 10     }); });  $('.scroll-top').click(function() {      $('.tableholder').animate({         scrolltop: $('.tableholder').scrolltop() - 10     }); }); 

here fiddle http://jsfiddle.net/thiswolf/45glr/3/

what explanation can given explain why scrolltop worked in way?

when clicked on scroll-down button value of $('.tableholder').scrolltop() 0 , after event occurred it's value changed 0 + 10 = 10;

next, if clicked on scroll-top button value of $('.tableholder').scrolltop() 10 time , after event occurred it's value changed 10 - 10 = 0;

and thats, how goes down , up.

to make code, bit faster , better, can this:

var $tableholder = $('.tableholder'); $('.scroll-down').click(function () {     $tableholder.stop().animate({         scrolltop: $tableholder.scrolltop() + 10     }); }); $('.scroll-top').click(function () {     $tableholder.stop().animate({         scrolltop: $tableholder.scrolltop() - 10     }); }); 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -