【问题标题】:jQuery - Delete invisible div inside iFrame after X seconds?jQuery - X 秒后删除 iFrame 内的不可见 div?
【发布时间】:2012-12-18 04:09:45
【问题描述】:

基于此脚本:

jsFiddle

var W=0, H=0, X=0, Y=0;
$(".iframe").each(function(i,el){
   W = $(el).width();
   H = $(el).height();
   X = $(el).position().left;
   Y = $(el).position().top;
   $(this).after('<div class="overlay" />');
    $(this).next('.overlay').css({
        width: W,
        height: H,
        left: X,
        top: Y        
    });
});

// TRACK MOUSE POSITIONS (the overlay will prevent clicks on iframe page)
var mx = 0, my = 0;
$('.overlay').on('mousemove click',function(e){
    mx = e.clientX - $(this).position().left;
    my = e.clientY - $(this).position().top;

    if(e.type==='click'){
        alert('clicked at: X='+mx+' Y='+my)
    }        
});

是否可以在 X 秒后自动删除不可见的 div?

谢谢

【问题讨论】:

  • 我错了,当我说 div 时,我指的是覆盖 iframe 的层

标签: jquery


【解决方案1】:

已编辑:如果您想删除 iframe 的内容,可以点击此链接:
Unloading/Removing content from an iFrame 你应该把它放在这样的计时器中:

// delete after 3 seconds.
var myVar = setInterval(function(){myTimer()},3000);
function myTimer()
{
   // remove the div
   $('#yourDiv').remove();
}

有关 javascript 计时的更多信息,您可以点击此链接:JavaScript Timing Events
希望有所帮助。

【讨论】:

    【解决方案2】:

    将以下内容作为 on() 回调的一部分。

    window.setTimeout(function(){
                         $('.overlay').remove();
                      }, 10000); //10 sec delay
    

    详情请参阅setTimeout docs。您还需要删除显示坐标的标签。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-25
      • 2017-09-20
      • 1970-01-01
      • 2010-11-21
      • 2011-02-15
      • 2018-05-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多