Reputation: 9787
I try to click to a button and scroll.I can do it easily with html (option 1). But it jumps and I would like to control the speed to move slowly.
Then I tried jQuery (Option1) but I do not know how to tell to scroll 100% of the window and how to control the speed. Is it possible to do that with css or/and jQuery?
Option 1. Scroll with HTML:
http://jsfiddle.net/VPT4q/
<div id="first">
<a href="#second">
<div id="down"></div>
</a>
</div>
<div id="second"></div>
Option 2. Scroll with jQuery: http://jsfiddle.net/VPT4q/1/
$(function(){
$('#down').click(function() {
// window.scrollBy(0,200);
window.scrollTo(0,200);
});
})
Upvotes: 0
Views: 231
Reputation: 1065
$('#down').click(function () {
$('html, body').animate({ scrollTop: $('body').height() }, 1000);
});
//1000 is number of milliseconds
Upvotes: 3
Reputation: 7130
If you are going to do jQuery, I'd do it something like this:
$('#down').click(function() {
$('html,body').animate({scrollTop: $('#second').offset().top},'slow');
});
fiddle: http://jsfiddle.net/gJwUT/
May not be exactly what you want, but I think it will get you started.
You can tweak the speed by changing 'slow'
to a number. 'slow'
, I think, is 1 second. or '1000'
.
$('html,body').animate({scrollTop: $('#second').offset().top}, 2000 );
Upvotes: 1