例如,滚动到页面上的某个元素(例如:How to go to a specific element on page?)
$("#fromTHIS").click(function() {
$("html, body").animate({ scrollTop: $("#toTHIS").offset().top }, 500);
return true;
});我两个都试过了,看起来他们都做得很好。我遗漏了什么?
发布于 2018-01-31 15:06:05
$('html, body')似乎是跨浏览器滚动动画的jquery解决方案。
如果你想要一个没有动画的跨浏览器解决方案,你可以尝试这样做:
$(window).scrollTop(0);
// Accepts int of pixels.在最新的Chrome、Opera和FF上进行了测试。似乎可以跨浏览器工作。(除非有人能确认它在IE或Safari或其他平台上不起作用)
阅读有关jQuery scrollTop的更多信息。
发布于 2020-04-20 23:15:02
以下是跨浏览器动画的示例:
//('html, body') is the jquery solution for cross browser scroll animation $('html, body').animate({ scrollTop: $(".abc-container").offset().top+ "-50px" }, 300)
https://stackoverflow.com/questions/19303405
复制相似问题