Solve the problem of displaying errors based on the JQ Focus chart Quick Click toggle button Picture

Source: Internet
Author: User

Before using the original JS to do the focus map, today suddenly want to use JQ to do, but encountered a problem, when I kept clicking the toggle button, because the animated animate, resulting in the picture shows the problem of confusion, the first thing to think about is to click on the switch immediately after the event is resolved, Then the animation function runs out and then adds the event, but .... Use

$ ('. Box '). Unbind (' click ');

After the binding, and then add the original event back but there is no way to add back

$ ("button"). Bind ("click", Function () {  //body});

Such But the function of the body can not write, there may be a way to write but the more confused, then think of a better way

Add a flag listener variable, when the click-click event is flag==true and the flag is false in the event run, this solves the problem simply and conveniently. On the Code

var now=0;var flag=true;            This is it. $ ('. Prve '). Click (function () {if (flag) {Flag=false;now=parseint ($ (' ul '). CSS (' left ')), $ (' ul '). Animate ({left : now+500+ ' px '},300,function () {Now=parseint ($ (' ul '). CSS (' left ')), if (now>= 0) {$ (' ul '). CSS (' left ', ' -2500px ');} Flag=true;     In this});})

Yes, there is one more thing that cannot be placed outside of the animate () method's callback function, because animate () animations can change the value of the flag, the outside function is executed when the animation () is executed, and the animate animation will still not solve the problem in the order of execution.

JS is a single-threaded language, so there has to be a sequence.

Solve the problem of displaying errors based on the JQ Focus chart Quick Click toggle button Picture

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.