Animate animation Second Click event in jquery no response _jquery

Source: Internet
Author: User
Tags numeric value

Using animate to do the click-Flip animation found that the second click event Animation did not respond, and the first click has animation effect, the code is as follows:

Copy Code code as follows:

$ (". Page"). Stop (). Animate ({top: " -300px"}, A, ' easeinoutexpo ');

The second click event Animation did not respond to the reason: the top is the distance from the front of the page element to the top of its parent, and after the first click, the top of the page is moved to the position of the top of its parent element, and the second click is not the page -300px the 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 top:-300px move distance is 0, therefore does not respond.
Workaround:

Copy Code code as follows:

$ (". Page"). Stop (). Animate ({top: "-=300px"}, A, ' easeinoutexpo ');

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

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

 
function down () {
var page_h=$ ('. Page '). Height ();//687
var page_top=parseint ($ (". Page"). CSS ("top");//0
var move=wrap_top+page_h;
$ (". Page"). Stop (). Animate ({Top:move}, a, ' Easeinoutexpo ');

var page_h=$ (". Page"). Height (); Gets the height of the page and assigns the value to Page_h, which is the numeric value;
var page_top=parseint ($ (". Page"). CSS ("top"); Gets the distance at the top of the current page to its parent element and assigns it to Page_top, (parseint: Remove "PX");
var move=wrap_top+page_h, calculating the moving distance;

This way, each animation retrieves 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, $ (". Page"). The value of the CSS ("top") is a PX unit, which requires parseint unit PX pixel units to be deleted to calculate.

The above mentioned is the entire content of this article, I hope you can enjoy.

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.