开发者

scroll to a div

开发者 https://www.devze.com 2023-04-01 09:39 出处:网络
I am trying to use a very basic smooth scrolling feature with jQuery\'s scrollTop function, but no success.

I am trying to use a very basic smooth scrolling feature with jQuery's scrollTop function, but no success. I want that any of the link which has css class "scroll" should always scroll down the page and stop at a div which has a class "stop". For example, I have HTML structure like:

<a href="#" class="scroll开发者_高级运维">Scroll down</a>
<div class = "test">long text</div>
<div class = "stop">Stop here</div>
<div class = "other">text</div>


Try this:

$('a.scroll').click(function() {
    var stop = $(this).siblings('div.stop:first').offset().top;
    var delay = 2000;
    $('body').animate({scrollTop: stop}, delay);
});


Take a look at jQuery scrollTo plugin. It will help you make your life easier.

http://plugins.jquery.com/project/ScrollTo

0

精彩评论

暂无评论...
验证码 换一张
取 消