所以,这个脚本在我的footer.php中,当按钮被按下时,它会重定向到主页而不是顶部。
$(document).ready(function() {
$("#arriba").click(function() {
return $("html, body").animate({
scrollTop: 0
}, 1250), !1
})
});
更新:
非常感谢,我找到了解决方案,上面的代码被插入到一个php实例中,我从php中创建了一个新的javascript实例,它在这里展示的所有代码都工作得很好!
您需要使用preventDEfault来阻止按钮或锚标记的行为:
$(document).ready(function() {
$("#arriba").click(function(e) {
e.preventDefault()
$("html, body").animate({
scrollTop: 0
}, 1250);
})
});
编辑:也试试这个:
$(document).ready(function() {
$("#arriba").click(function(e) {
e.preventDefault()
window.scrollTo(0, 0);
})
});