use*_*601 5 javascript safari smooth-scrolling scrolltop
我使用以下代码在菜单链接和内容行容器之间进行平滑滚动。除Safari之外,这在所有浏览器上似乎都可以正常工作。
我知道我需要在偏移线内定义“ html”和“ body”,但是,我不确定是否正确执行了此操作。希望对此有所帮助!谢谢。
$(function() {
$('a[href*="#"]:not([href="#"])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
var target = $(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html, body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
582 次 |
| 最近记录: |