Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/433.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 - Fatal编程技术网

Javascript 如何使用动画在jQuery中滚动?

Javascript 如何使用动画在jQuery中滚动?,javascript,Javascript,我想用动画从顶部滚动我的页面1750px。我尝试了以下方法,但不起作用 $('#trailer').click(function() { event.preventDefault(); //$(window).scrollTop(1750); // I want to animate this. $(window).animate( {top: 1750}, 200); return false; }); 您需要使用scrollT

我想用动画从顶部滚动我的页面1750px。我尝试了以下方法,但不起作用

$('#trailer').click(function() {
    event.preventDefault();
    //$(window).scrollTop(1750); // I want to animate this.
    $(window).animate(
        {top: 1750},
        200);
    return false;
});

您需要使用
scrollTop
而不是top,并且必须在
主体上调用animate
(或者
html
body
,具体取决于浏览器):


您需要使用
scrollTop
而不是top,并且必须在
主体上调用animate
(或者同时调用
html
body
,具体取决于浏览器):

$('html, body').animate({
  scrollTop: 1750
}, 200);