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