首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >向右动画div元素

向右动画div元素
EN

Stack Overflow用户
提问于 2019-01-11 14:52:48
回答 2查看 55关注 0票数 0

我想动画的div元素,以移动到右边时,‘登录’按钮被点击。

我已经设法将它动画到右边,但是其中一些元素挂在浏览器窗口上。

HTML:

代码语言:javascript
复制
<section class="welcome">
        <div class="hero-container">
                <h1 id="welcome">Welcome!</h1>
                <p>Welcome back</p>
                <button id="sign-in">Sign in</button>
                <button id="sign-up">Sign up</button>
    </div>

    <div class="form">
        <form class="sign-in">
            <h1 id="signIn-heading">Sign In</h1>

            <input type="text" name="email" placeholder="Email">

            <input type="text" name="pass" placeholder="Password">

        </form>
    </div>

</section>

jQuery:

代码语言:javascript
复制
$("#sign-in").click(function(){

//below I am retrieving the width of the body
var $width= $("body").width();

//assigning the body with to the animate method
$(".hero-container").animate({"left": $width}, "slow");

$("#welcome").html("Sign In");
$(".form").show();

});

这就是我想要实现的https://ibb.co/gmqZCkg 这就是我遇到的问题(您可以看到,一旦元素被动画化,它就挂在浏览器上) https://ibb.co/WP4vHLj

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-01-11 15:00:55

试试这个:

代码语言:javascript
复制
$("#sign-in").click(function(){

//below I am retrieving the width of the body
var $width= $("body").width()/2;

//assigning the body with to the animate method
$(".hero-container").animate({"left": $width}, "slow");

$("#welcome").html("Sign In");
$(".form").show();

});
代码语言:javascript
复制
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<section class="welcome">
        <div class="hero-container">
                <h1 id="welcome">Welcome!</h1>
                <p>Welcome back</p>
                <button id="sign-in">Sign in</button>
                <button id="sign-up">Sign up</button>
    </div>

    <div class="form">
        <form class="sign-in">
            <h1 id="signIn-heading">Sign In</h1>

            <input type="text" name="email" placeholder="Email">

            <input type="text" name="pass" placeholder="Password">

        </form>
    </div>

</section>

票数 1
EN

Stack Overflow用户

发布于 2019-01-11 14:59:55

你的动画量(宽度)是身体的宽度。您将需要获得#登录元素的宽度。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54148884

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档