Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/417.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_Delay - Fatal编程技术网

Javascript 分段jQuery在第二次迭代后淡入淡出

Javascript 分段jQuery在第二次迭代后淡入淡出,javascript,jquery,animation,delay,Javascript,Jquery,Animation,Delay,因此,我有以下听众: .on('click', function () { if ($('.forum-select-button, .compareToTotal').css('display') == 'none') { $('.metric-number, .compareToTotal').each(function (i) { $(this).delay((Math.floor(i / (data.columnNames.length +

因此,我有以下听众:

.on('click', function () {
    if ($('.forum-select-button, .compareToTotal').css('display') == 'none') {
        $('.metric-number, .compareToTotal').each(function (i) {
            $(this).delay((Math.floor(i / (data.columnNames.length + 1)) + 1) * 250).fadeOut('slow', function () {
                $('.forum-select-button').each(function (i) {
                    $(this).delay((Math.floor(i / (data.columnNames.length + 1)) + 1) * 250).fadeIn('slow');
                });
            });
        });
    } else {
        $('.forum-select-button').each(function (i) {
            $(this).delay((Math.floor(i / (data.columnNames.length + 1)) + 1) * 250).fadeOut('slow', function () {
                $('.metric-number, .compareToTotal').each(function (i) {
                    $(this).delay((Math.floor(i / (data.columnNames.length + 1)) + 1) * 250).fadeIn('slow');
                });
            });
        });
    }
})

论坛选择按钮
按钮默认设置为
显示:无
,而
度量值
比较总数
则设置为
显示:块
。第一组可以工作,因为数字会逐渐消失,按钮也会出现,但是如果您再次单击按钮,会出现长时间的暂停,数字会重新出现,并且按钮会非常缓慢地重新出现。更改延迟似乎没有任何作用。

最后,我将延迟写入setTimeout来修复它。以下是我的解决方案:

.on('click', function(){
    if($('.forum-select-button, .compareToTotal').css('display') == 'none'){
        $('.metric-number, .compareToTotal').each(function(i){
            setTimeout(function(){
                $(this).fadeOut('slow', function(){
                    $('.forum-select-button').each(function(i){
                        setTimeout(function(){
                            $(this).fadeIn('slow');
                        }.bind(this), (Math.floor(i / (data.columnNames.length + 1)) + 1) * 250);
                    });
                });
            }.bind(this), (Math.floor(i / (data.columnNames.length + 1)) + 1) * 250);
        });
    } else {
        $('.forum-select-button').each(function(i){
            setTimeout(function(){
                $(this).fadeOut('slow', function(){
                    $('.metric-number, .compareToTotal').each(function(i){
                        setTimeout(function(){
                            $(this).fadeIn('slow');
                        }.bind(this), (Math.floor(i / (data.columnNames.length + 1)) + 1) * 250);
                    });
                });
            }.bind(this), (Math.floor(i / (data.columnNames.length + 1)) + 1) * 250);
        });
    }
})

工作起来很有魅力:)

那是什么
.bind(section)
?你想产生什么效果?当
度量值
比较总数
消失时,您希望论坛选择按钮出现吗?还是希望它们在全部消失后出现?@falsarella这实际上是此onclick侦听器中最后一个函数的残余。我已经删除了它,我将编辑帖子。@Stryner Yea确切地说,我希望该行的度量值和compareToTotal消失,并显示“论坛选择”按钮,然后对下一行显示相同的按钮,直到所有行都完成。这对我的第一次点击有效,但第二次通话的第一次延迟似乎破坏了一切。