Javascript 如何使用动画在jQuery中滚动?
我想用动画从顶部滚动我的页面1750px。我尝试了以下方法,但不起作用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
$('#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);