我一直在用头撞墙,尝试使用大量平滑滚动插件来解决注册按钮无法正常向下滚动到#target 部分的问题。
请帮助 hive mind,我正在使用 CSS 技巧代码。
$('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;
}
}
});
你可以在
看到带有所有 html css 和其他 js 的笔最佳答案
取消你的代码并尝试这个代码(它可能会有点快,可能将它更改为 500),如果你的按钮和 anchor 之间有太多内容,它可能会有点滞后:
/*Scroll Down Button*/
$(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;
}
}
});
});
关于javascript - 平滑滚动无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43634187/