jquery - HTML Div 滚动到另一个 Div

标签 jquery html css

我有 1 个 Div,“read-more hvr-pulse”,我希望当用户单击该 DIV 时发生一个事件。我希望它滚动到另一个 Div,这是页面下方的登录表单。

我尝试了一个围绕 DIV 的样式,但这导致了样式方面的几个问题,最终它没有工作。我对 JS 相当陌生,所以简单性会令人惊奇。

保存登录名的 DIV 称为“eUser”

基本上我只是希望 DIV“read-more hvr-pulse”顺利滚动到“eUser”。任何帮助将不胜感激。

HTML

<div class="Main animated fadeIn">
    <!--To make the Site Unique, I have included Several Trailers for the Main Landing Page !-->
    <video autoplay loop poster="polina.jpg" id="bgvid">
        <source src="img/indexMV.webm" type="video/webm">
        <source src="img/indexMV.webm" type="video/mp4">
    </video>
</div>
<!--For Style Purposes, I have wrapped the Login and Register Section of the site in a Container !-->
<div class="eUser">
    <div class="container">
        <div class="login animated bounceInDown" >
            <form class="form-3" action="logreg.php" method="post" accept-charset="utf-8">
                <label>Username: </label><input type="text" name="username" value="" placeholder="Username">
                <br />
                <label>Password: </label><input type="password" name="password" value="" placeholder="Password">
                <br />
                <input class="Login hvr-pulse" type="submit" name="login" value="Login">
                <input class="Register hvr-pulse" type="submit" name="register" value="Register">
            </form>
        </div>
    </div>
</div>
<!-- The code below is The Text for the Landing Page -->
<section class="start-page parallax-background" id="home">
    <div class="content">
    <div class="text">
    <h1>Welcome to our User Login Page. Please Select Your User Type</h1>
    <hr/>
    <div class="read-more hvr-pulse">New User</div>
    <div class="eUser hvr-pulse">Existing User</div>
    <div class="Admin hvr-pulse">Admin</div>
</section>

最佳答案

使用animate()函数和 scrollTop 平滑滚动到某个元素。

$(document).on('click', '.read-more.hvr-pulse', function(){
  $('html,body').animate({
        scrollTop: $('.eUser').offset().top
  },'slow');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="Main animated fadeIn">
    <!--To make the Site Unique, I have included Several Trailers for the Main Landing Page !-->
    <video autoplay loop poster="polina.jpg" id="bgvid">
        <source src="img/indexMV.webm" type="video/webm">
        <source src="img/indexMV.webm" type="video/mp4">
    </video>
</div>
<!--For Style Purposes, I have wrapped the Login and Register Section of the site in a Container !-->
<div class="eUser">
    <div class="container">
        <div class="login animated bounceInDown" >
            <form class="form-3" action="logreg.php" method="post" accept-charset="utf-8">
                <label>Username: </label><input type="text" name="username" value="" placeholder="Username">
                <br />
                <label>Password: </label><input type="password" name="password" value="" placeholder="Password">
                <br />
                <input class="Login hvr-pulse" type="submit" name="login" value="Login">
                <input class="Register hvr-pulse" type="submit" name="register" value="Register">
            </form>
        </div>
    </div>
</div>
<!-- The code below is The Text for the Landing Page -->
<section class="start-page parallax-background" id="home">
    <div class="content">
    <div class="text">
    <h1>Welcome to our User Login Page. Please Select Your User Type</h1>
    <hr/>
    <div class="read-more hvr-pulse">New User</div>
    <div class="eUser hvr-pulse">Existing User</div>
    <div class="Admin hvr-pulse">Admin</div>
</section>

关于jquery - HTML Div 滚动到另一个 Div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34784387/

相关文章:

jquery - 在 jQuery 中,尝试获取下一个没有特定类的项目

php - 如何在replaceWith()中使用.load的结果

javascript - 日期选择器的动态年份范围

javascript - 使用 jQuery 淡入淡出背景图像

javascript - 单击 'submit' 时将复选框值传递给 js

javascript - 播放音频 html 标签不起作用

html - 包含面板列表的引导面板主体内的水平滚动

css - 提交按钮无法输入

javascript - 如何更改悬停时的图标颜色?

html - 如何将 CSS 设置应用于特定的 HTML 元素