我正在scrollTo()网页上尝试,我想要一个按钮来触发scrollTo(); 它将滚动到窗体的顶部并突出显示第一个输入字段.
我当前的代码有效,但屏幕快速闪烁.我试图使用一个preventDefault()无济于事.请参阅下面的代码.
$(document).ready(function () {
$("#get-started").click(function (e) {
e.preventDefault();
$('html, body').animate({
scrollTop: $("#get-risk").offset().top
}, 2000);
$("#get-started-apply-now-form [name='last_name']").focus();
});
});
Run Code Online (Sandbox Code Playgroud)