JavaScript 实现 ScrollTo 带动画效果
可以使用 jQuery 的 animate() 函数来实现 scrollto 的时间动画效果。例如:
$('html, body').animate({
scrollTop: $('#target-element').offset().top
}, 1000); // 1000毫秒为动画时间,可以根据需要调整
这段代码将页面滚动到 id 为 'target-element' 的元素处,动画时间为 1000 毫秒。需要注意的是,这里使用了 'html, body' 来支持不同浏览器的兼容性。
原文地址: http://www.cveoy.top/t/topic/mGqO 著作权归作者所有。请勿转载和采集!