Animate animation Second Click event Not responding in jquery

Source: Internet
Author: User

Animate animation Second Click event Not responding in jquery

When animating a click-to-page animation, the second click event Animation does not respond, and the first click has an animated effect, the code is as follows:

Copy CodeThe code is as follows:
$ (". Page"). Stop (). Animate ({top: " -300px"}, +, ' easeinoutexpo ');

The second Click event Animation does not respond to the reason: top is the page element at the top and the top of its parent element of the distance, after the first click, the page element top has moved to the top of its parent element -300px position, the second click is not the page in the position after the move to continue T move -300px, Instead, the current position is -300px at the top of its parent element. Obviously the first time has moved to the top:-300px position, the second time the top:-300px movement distance is 0, therefore did not respond.
Workaround:

Copy CodeThe code is as follows:
$ (". Page"). Stop (). Animate ({top: "-=300px"}, +, ' easeinoutexpo ');

Top: "-=300px", so that the second click will continue to move the -300px after the first click.

If the distance the animation moves is a variable, it cannot be written with "-= variable name":

?
123456 function down () { var page_h=$ ( ". Page " ). Height (); //687 var page_ Top=parseint ($ ( "top" //0 var move=wrap _top+page_h; $ ( ' Easeinoutexpo '

var page_h=$ (". Page"). Height (), gets the height of the page and assigns a value to the Page_h, the value is the number;
var page_top=parseint (". Page"). CSS ("top"), gets the distance from the top of the current page to the top of its parent element and assigns a value to Page_top, (parseint: Remove "PX");
var move=wrap_top+page_h; calculate moving distance;

This way each animation will regain the "distance from the top of the current page to the top of its parent element."

Note: $ (". Page"). The value of height () is not in PX units, and $ (". Page"). CSS ("top") values are in PX units and need to be removed by parseint units px pixels in order to be calculated.

The above mentioned is the whole content of this article, I hope you can like.

Animate animation Second Click event Not responding in jquery

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.