Below is a very simple example, where content of a list is being scrolled by two buttons.
So lets get into this,
1. First we need to create a div tag with it's style overflow attribute set to hidden.
2. Add the content.
3. Now for scrolling, we will use jquery's animate function which will provide us a smooth scrolling effect.
function scroll(val) { jQuery('#list').animate({ scrollTop: jQuery('#list').scrollTop() + (val) }, 450); }The above function takes a integer parameter which gets added to the scrollTop attribute of the div containing the content, which causes the content to scroll. The animate function makes the transition smoother, to read more about animate function go here.
4. Now what we need is just two buttons, which will call this function and pass +ve values to scroll down and -ve values to scroll up.
This a very simple example, but gives a good idea for building cool vertical content scrolling.
Very useful!!!
ReplyDelete