2

我有这个带有注册表单的 html 代码,我需要在单击带有类 .reg 的按钮后向上滚动页面。问题是页面仅滚动到表单的上边界。

<div class='registration borders'>

<form action="{$web_path}/model/user/userRegistration.php" method="post">

<input class='user' type='text' name='user' autofocus required placeholder="uživatelské jméno">
<input class='email' type='email' name='email' required placeholder="Váš e-mail">

<input class='password' type='password' name='password' required placeholder="uživatelské heslo">

<button class='reg' type='submit' name='registration_sent'>ZAREGISTROVAT</button>

</form>

</div>

Javascript代码

$(document).ready(function () {
    var button_reg = $('button.reg');
    button_reg.click(function () {

        // scroll top
        $('html, body').animate({
            scrollTop: 0
        }, 'slow');
    });

    // end jquery
    return false;
}); 
4

1 回答 1

0

尝试这样的事情:

$(document).ready(function(){
$('#button').click(function(){
$('html, body').animate({scrollTop: $("#your_respective_div").offset().top}, 1000);
});
})
于 2013-07-02T15:35:31.973 回答