【问题标题】:Style the iframe and then make it visible为 iframe 设置样式,然后使其可见
【发布时间】:2014-07-16 03:03:25
【问题描述】:

我在我的网站中使用 iframe 中的 Twitter 小部件。我正在设计这个 iframe 没有任何问题。 我遇到的问题是我首先看到旧的 iframe,然后我可以看到样式的变化。 有没有办法在背景发生所有 css/样式更改时隐藏 iframe,然后使其可见?

我使用这个 jquery:

 $(document).ready(function(){
    hideTwitterBoxElements();
 });

 var hideTwitterAttempts = 0;

 function hideTwitterBoxElements() {
   setTimeout( function() {

    if ( $('[id*=twitter]').length ) {
        $('[id*=twitter]').each( function(){
            var ibody = $(this).contents().find( 'body' );

            ibody.find(".timeline .stream").css("padding-top", "10px")

            if ( ibody.find(".timeline .stream .h-feed li.tweet").length ) 

                ibody.find(".timeline").css("background-color","transparent");  
                ibody.find(".customisable-border").css("border","none");    
                ibody.find(".timeline .stream").css("overflow","hidden");   

            }
        });
    }
    hideTwitterAttempts++;
    if ( hideTwitterAttempts < 3 ) {
        hideTwitterBoxElements();
        $("#twitter").show();
    }
}, 1500);

}

当我加载页面时,iframe 会在一段时间后出现(如果可能的话,我也想减少时间)然后我可以看到例如溢出变为隐藏。

提前致谢。

【问题讨论】:

  • 您能在jsbin.com 上重现您的问题吗?

标签: javascript jquery css iframe twitter


【解决方案1】:

编辑:

将您的代码与this one 混合在一起,我们得到了非常好的结果。

JSFiddle

function hideTwitterBoxElements() {

    var hideTwitterAttempts = 0;

    if ($('.twitter-timeline').length) {
        //Timeline exists is it rendered ?
        interval_timeline = false;
        interval_timeline = setInterval(function(){
            //console.log($('.twitter-timeline').width());
            if ($('.twitter-timeline').hasClass('twitter-timeline-rendered')) {
                if ($('.twitter-timeline').width() > 10) {
                    //Callback
                    clearInterval(interval_timeline);
                    setTimeout( function() {
                        if ( $('[id*=twitter]').length ) {
                            $('[id*=twitter]').each( function(){
                                var ibody = $(this).contents().find( 'body' );
                                ibody.find(".timeline .stream").css("padding-top", "10px");
                                if ( ibody.find(".timeline .stream .h-feed li.tweet").length ); 
                                ibody.find(".timeline").css("background-color","transparent");  
                                ibody.find(".customisable-border").css("border","none");    
                                ibody.find(".timeline .stream").css("overflow","hidden");
                            });
                        }
                        hideTwitterAttempts++;
                        if ( hideTwitterAttempts < 40 ) {
                            hideTwitterBoxElements();
                            $("#twitter").show();
                        }
                    }, 100);
                }     
            }
        },200);
    }
}

$(document).ready(function(){
    hideTwitterBoxElements();
});

【讨论】:

  • 我已经这样做了。你可以在我的代码中看到我有 $("#twitter").show();这正是你所说的。但仍然没有按照我想要的方式工作。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-02
  • 2011-05-25
  • 2015-12-22
  • 1970-01-01
  • 1970-01-01
  • 2022-11-04
相关资源
最近更新 更多