-1

我试图让网站滚动到锚点而不跳转。该网站是www.nicbrwn.com/vision

任何帮助,将不胜感激。我在这里试过这个例子:http: //css-tricks.com/snippets/jquery/smooth-scrolling/但它仍然只是跳跃。

4

1 回答 1

1

干得好

html

<a href="#red">red</a>  <a href="#blue">blue</a>
<div class="section red" id="red"></div>
<div class="section blue" id="blue"></div>

的CSS

.section {
height:550px;
}
.red {
background-color:#F00;
}
.blue {
background-color:#036;
}

JS

$('a[href*=#]:not([href=#])').click(function () {
if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') || location.hostname == this.hostname) {

    var target = $(this.hash);
    target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
    if (target.length) {
        $('html,body').animate({
            scrollTop: target.offset().top
        }, 1000);
        return false;
    }
}
});

演示 http://jsfiddle.net/cancerian73/k2j5X/

于 2013-11-13T04:25:52.570 回答