Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/github/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery:在动画期间禁用单击_Javascript_Jquery_Animation_Click_Unbind - Fatal编程技术网

Javascript jQuery:在动画期间禁用单击

Javascript jQuery:在动画期间禁用单击,javascript,jquery,animation,click,unbind,Javascript,Jquery,Animation,Click,Unbind,因此,我做了一个小测验,我想在动画运行时禁用对#qWrap中所有内容的单击,从而防止垃圾邮件单击。 我尝试使用.is(':animated'),但没有效果。有什么想法吗 HTML: 您的JS代码应该如下所示: $('.qAnswers li a').bind('click', function(event) { event.preventDefault(); //preventing click within #qWrap if ($('#qWrap').is(':a

因此,我做了一个小测验,我想在动画运行时禁用对
#qWrap
中所有内容的单击,从而防止垃圾邮件单击。 我尝试使用
.is(':animated')
,但没有效果。有什么想法吗

HTML:


您的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')是(':animated')
不是在元素设置动画时触发的事件,它是正常检查。我移动了你的
事件.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();
});
$('[where you click]').click(
function(){
    if(!$('[what animates]').is(':animated')){
        $('[what animates]').[your_animation];
    }
});

代码
$('#qWrap')是(':animated')
不是在元素设置动画时触发的事件,它是正常检查。我移动了你的
事件.preventDefault()也显示在顶部;我想你无论如何都想这么做。您可能还需要处理一些其他问题。

您能为我们提供一个JSFIDLE链接,以便我们进行测试吗?但我并没有让它完美地工作:你能为我们提供一个JSFIDLE链接以便我们进行测试吗?不过我并没有让它工作得很好:谢谢你的清理,并没有真正解决我的问题though@CarlPapworth好啊试着看看发生了什么。谢谢你的清理,并没有真正解决我的问题though@CarlPapworth好啊试着看看发生了什么。
$('[where you click]').click(
function(){
    if(!$('[what animates]').is(':animated')){
        $('[what animates]').[your_animation];
    }
});