Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.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
Jquery 将此与setTimeOut函数一起使用已停止工作_Jquery_Settimeout_Each - Fatal编程技术网

Jquery 将此与setTimeOut函数一起使用已停止工作

Jquery 将此与setTimeOut函数一起使用已停止工作,jquery,settimeout,each,Jquery,Settimeout,Each,我创建了一个函数,使用。每个函数循环父div中的div,名为“rolloverimages”。我希望在生成每个图像的时间之间有一个延迟,因此我使用setTimeOut。我的问题是,只要我添加了setTimeOut函数,使用this中的变量就与主rollovers变量无关 有人能帮忙吗 function rolloverImages() { $('.thumbnail-wrapper').one('mouseover', function() { var rollover

我创建了一个函数,使用
。每个
函数循环父div中的div,名为“rolloverimages”。我希望在生成每个图像的时间之间有一个延迟,因此我使用
setTimeOut
。我的问题是,只要我添加了setTimeOut函数,使用
this
中的变量就与主
rollovers
变量无关

有人能帮忙吗

function rolloverImages() {

    $('.thumbnail-wrapper').one('mouseover', function() {
        var rollovers = $(this).find('.rolloverimages div');
        var time = 0;

        rollovers.each(function() {
            setTimeout(function() {
                var datasrc = $(this).data('hover');
                var img = $('<img id="dynamic">');
                var imgsrc = img.attr('src', datasrc);
                var parent = $(this).parent('.rolloverimages').parent('.thumbnail-wrapper');
                console.log(parent);
            }, time);
            time += 2000;
        });
    }); 
}
函数rollvirimages(){
$('.thumbnail wrapper').one('mouseover',function(){
var rollovers=$(this.find('.rolloverimages div');
var时间=0;
滚动。每个(函数(){
setTimeout(函数(){
var datasrc=$(this.data('hover');

var img=$('您必须在setTimeout调用之前添加var that=this(并使用它代替this),或者将函数绑定到此:

function rolloverImages() {

          $('.thumbnail-wrapper').one('mouseover', function() {
            var rollovers = $(this).find('.rolloverimages div');
            var time = 0;

            rollovers.each(function() {
               setTimeout(function() {
                  var datasrc = $(this).data('hover');
                  var img = $('<img id="dynamic">');
                  var imgsrc = img.attr('src', datasrc);
                  var parent = $(this).parent('.rolloverimages').parent('.thumbnail-wrapper');
                  console.log(parent);
                }.bind(this), time);
                time += 2000;
            });

        });

    }
函数rollvirimages(){
$('.thumbnail wrapper').one('mouseover',function(){
var rollovers=$(this.find('.rolloverimages div');
var时间=0;
滚动。每个(函数(){
setTimeout(函数(){
var datasrc=$(this.data('hover');
变量img=$('