jQuery技术:jQuery:在动画期间禁用点击

所以我正在进行一个小测验,我希望在动画运行时禁用#qWrap内部的所有内容,从而防止垃圾邮件点击。 我尝试使用.is(':animated')但没有效果。 有任何想法吗?

HTML:

  

JS:

 $('.qAnswers li a').bind('click', function(event) { $(this).parent().addClass('selected'); $(this).closest('.qAnswers').find("li:not(.selected, .qQuestion)").delay(200).addClass('notSelected'); var $anchor = $(this); //preventing click within #qWrap if ($('#qWrap').is(':animated')) { $('#qWrap').unbind('click'); } //firing the animation $('#qWrap').stop(true, true).delay(800).animate({ scrollLeft: $($anchor.attr('href')).position().left }, 2000, function() { nextCount(); }); stopTimer(); addData(); event.preventDefault(); }); 

    您的JS代码应如下所示:

     $('.qAnswers li a').bind('click', function(event) { event.preventDefault(); //preventing click within #qWrap if ($('#qWrap').is(':animated')) { return; } $(this).parent().addClass('selected'); $(this).closest('.qAnswers').find("li:not(.selected, .qQuestion)").delay(200).addClass('notSelected'); var $anchor = $(this); //firing the animation $('#qWrap').stop(true, true).delay(800).animate({ scrollLeft: $($anchor.attr('href')).position().left }, 2000, function() { nextCount(); }); stopTimer(); addData(); }); 

    代码$('#qWrap').is(':animated')不是在元素动画时触发的事件,它是正常检查。 我移动了你的event.preventDefault(); 到顶部; 想你想做到这一点,无论如何。 您可能还需要移动其他一些东西。

    需要了解更多jQuery教程分享jQuery:在动画期间禁用点击,都可以关注jQuery技术分享栏目—计算机技术网(www.ctvol.com)!

     $('[where you click]').click( function(){ if(!$('[what animates]').is(':animated')){ $('[what animates]').[your_animation]; } }); 

      以上就是jQuery教程分享jQuery:在动画期间禁用点击相关内容,想了解更多jQuery开发(异常处理)及jQuery教程关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/jquerytutorial/982292.html

      (0)
      上一篇 2021年12月13日
      下一篇 2021年12月13日

      精彩推荐