Jquery 开始滚动时向下滚动到目标

Jquery 开始滚动时向下滚动到目标,jquery,Jquery,这就是我想要做的:如果你在页面的顶部并开始向下滚动,你应该自动向下滚动到div#content。如果我使用下面的代码,则无法使用动画滚动到页面上的其他链接,并且在页面使用下面的代码向下滚动到#内容后,我根本无法滚动 $(window).scroll(function () { var content = $('#content'); $('html, body').animate({ scrollTop: content.offset().top },

这就是我想要做的:如果你在页面的顶部并开始向下滚动,你应该自动向下滚动到div#content。如果我使用下面的代码,则无法使用动画滚动到页面上的其他链接,并且在页面使用下面的代码向下滚动到#内容后,我根本无法滚动

$(window).scroll(function () { 
    var content = $('#content');
    $('html, body').animate({
        scrollTop: content.offset().top
    }, 1000);
    return false;
});
试试这个

jQuery(document).ready(function () { 
     $("a").click(function(e){     
         e.preventDefault();      
         $('html, body').animate({
            scrollTop: $($(this).attr('href')).offset().top
        }, 1000); 
    });
});

我这里有两个版本,选择兄弟

1.

jQuery(document).ready(function () {
    if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
        $(this).bind('DOMMouseScroll', function (e) {
            if (e.originalEvent.detail > 0) {
                $('html, body').delay(200).animate({
                    scrollTop: $('#content').offset().top
                }, 1000);
            }
        });
    } else {
        $(this).bind('mousewheel', function (e) {
            if (e.originalEvent.wheelDelta / 120 < 1) {
                $('html, body').delay(200).animate({
                    scrollTop: $('#content').offset().top
                }, 1000);
            }
        });
    }
});
var scrolling = false;    

jQuery(document).ready(function () {
    $(window).scroll(function () {
        if ( $(window).scrollTop() <= 100 && scrolling === false) {
            //set to true to prevent multiple scrolls
            scrolling = true; 

            //run the animation 
            $('html, body').animate({
                scrollTop: $('#content').offset().top
            }, 1000, function() {
                //when animation is complete, set scrolling to false
                scrolling = false; 
            });
        }

    });
});
jQuery(文档).ready(函数(){
if(navigator.userAgent.toLowerCase().indexOf('firefox')>-1){
$(this).bind('DOMMouseScroll',函数(e){
如果(e.originalEvent.detail>0){
$('html,body')。延迟(200)。设置动画({
scrollTop:$('#content').offset().top
}, 1000);
}
});
}否则{
$(this).bind('mouseweel',函数(e){
如果(例如,原始事件车轮三角形/120<1){
$('html,body')。延迟(200)。设置动画({
scrollTop:$('#content').offset().top
}, 1000);
}
});
}
});
我的版本

2.

jQuery(document).ready(function () {
    if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1) {
        $(this).bind('DOMMouseScroll', function (e) {
            if (e.originalEvent.detail > 0) {
                $('html, body').delay(200).animate({
                    scrollTop: $('#content').offset().top
                }, 1000);
            }
        });
    } else {
        $(this).bind('mousewheel', function (e) {
            if (e.originalEvent.wheelDelta / 120 < 1) {
                $('html, body').delay(200).animate({
                    scrollTop: $('#content').offset().top
                }, 1000);
            }
        });
    }
});
var scrolling = false;    

jQuery(document).ready(function () {
    $(window).scroll(function () {
        if ( $(window).scrollTop() <= 100 && scrolling === false) {
            //set to true to prevent multiple scrolls
            scrolling = true; 

            //run the animation 
            $('html, body').animate({
                scrollTop: $('#content').offset().top
            }, 1000, function() {
                //when animation is complete, set scrolling to false
                scrolling = false; 
            });
        }

    });
});
var scrolling=false;
jQuery(文档).ready(函数(){
$(窗口)。滚动(函数(){

if($(window).scrollTop())我忘了说我在#内容中有一个菜单。如果我添加这个jquery代码,链接就不起作用。当我转到#内容时,我根本无法滚动。我使用这个链接到菜单链接:$($nav ul li a”)。单击(函数(e){e.preventDefault();var target=$($(this.attr('href');$('html,body')。动画({scrollTop:target.offset().top},1000);返回false;});你的a标签的结构是什么?像这样的东西吗?
是的,我有我的链接结构。我更新了上面的答案,兄弟..如果正确的话。希望对你有帮助。我想你需要这样的东西。你在找那种东西吗?你的意思是你需要知道卷轴何时开始,以及当前偏移量是多少anks.1版可以在chrome和Safari中使用,但不能在Firefox中使用。试试这个兄弟。我还在IE、FF中测试了它,工作正常。1版的脚本也更新了。