开发者

scroll to a div

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜