Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
219 views
in Technique[技术] by (71.8m points)

javascript - JQuery animation effects immediately revert after animation

I feel like I am going crazy here. I am playing around with JQuery animation. Something I haven't really used since school.

I am doing something super simple. I have a div that is just a square that is 150px by 150px I am using JQuery to animate it to grow the width. As soon as the animation completes, the square reverts back to the original dimensions.

Now I seem to remember that the animation effects would stay changed once the animation completes. Has this changed? Or am I simply misremembering how this works? All the examples I have seen on W3 schools and such have the animation stay once it is complete.

        #square
        {
            width: 150px;
            height: 150px;
            background-color: red;
            margin:10px;
        }
            $("#square").click(function(){
                (this).animate({width:"400px"}, 2000);
            });
question from:https://stackoverflow.com/questions/65913283/jquery-animation-effects-immediately-revert-after-animation

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

use $(this) that's the problem :

  $("#square").click(function(){
            $(this).animate({width:"400px"}, 2000);
        });

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...