Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript JQuery滚动动画瞬间在主屏幕上闪烁_Javascript_Jquery_Animation_Twitter Bootstrap 3 - Fatal编程技术网

Javascript JQuery滚动动画瞬间在主屏幕上闪烁

Javascript JQuery滚动动画瞬间在主屏幕上闪烁,javascript,jquery,animation,twitter-bootstrap-3,Javascript,Jquery,Animation,Twitter Bootstrap 3,我已经使用引导程序编写了一个菜单,它使用JQuery滚动到页面的不同部分,但在滚动前的一瞬间,主屏幕会闪烁。我不知道它为什么会发生,也不知道如何阻止它 $("#butHome").click(function() { $(".nav li").removeClass("active"); $(this).addClass("active"); $('html, body').animate({ scrollTop: $("#home").offset().top }, 300); });

我已经使用引导程序编写了一个菜单,它使用JQuery滚动到页面的不同部分,但在滚动前的一瞬间,主屏幕会闪烁。我不知道它为什么会发生,也不知道如何阻止它

$("#butHome").click(function() {
$(".nav li").removeClass("active");
$(this).addClass("active");
$('html, body').animate({
    scrollTop: $("#home").offset().top
}, 300);
});
$("#but1").click(function() {
$(".nav li").removeClass("active");
  $(this).addClass("active");
$('html, body').animate({
    scrollTop: $("#section1").offset().top
}, 300);
});
$("#but2").click(function() {
$(".nav li").removeClass("active");
  $(this).addClass("active");
$('html, body').animate({
    scrollTop: $("#section2").offset().top
}, 300);
}); 
$("#but3").click(function() {
$(".nav li").removeClass("active");
  $(this).addClass("active");
$('html, body').animate({
    scrollTop: $("#section3").offset().top
}, 300);
});
$("#but4").click(function() {
$(".nav li").removeClass("active");
  $(this).addClass("active");
$('html, body').animate({
    scrollTop: $("#section4").offset().top
}, 300);
}); 

可能是因为锚链接使页面在动画开始之前滚动到页面顶部。您可以通过在处理程序中添加以下内容来防止这种默认浏览器行为:

$('.upp').click(function(e){
    e.preventDefault();
    $.scrollTo( '#up', 800 );
});

复制了

您的scrollTo代码似乎重复了很多次,因此最好创建一个包含两个参数或一个参数的函数来处理它。嘿,谢谢,我不久前就解决了这个问题,但我很感谢您花时间来帮助我。没问题。。。永远在那里:D