iframe CSS Override for New Twitter Widget

后端 未结 8 1541
遇见更好的自我
遇见更好的自我 2021-01-04 07:03

I\'m trying to customise the new Twitter widget, but having some problems with the CSS and can\'t seem to override theirs on this new one. I\'ve tried searching for solution

8条回答
  •  无人及你
    2021-01-04 07:17

    This is without jQuery for anyone interested.

    UPDATED with much better solution that doesn't rely on polling and therefore doesn't have a flash of unstyled layout on occasion:

    twttr.events.bind('rendered',function(){
      [].slice.call(document.querySelectorAll('iframe.twitter-timeline')).forEach(function(e,i,a){
        var fE = e.contentDocument.getElementsByClassName('timeline-footer');
        if(fE.length){
          fE[0].style.backgroundColor='transparent';
        }
      });
    });
    

    old version:

    // Customize twitter feed                                                                              
    var hideTwitterAttempts = 0;                                                                           
    function hideTwitterBoxElements() {                                                                    
        setTimeout( function() {                                                                           
            var list = document.getElementsByTagName('iframe');                                            
            if (list.length ) {                                                                            
                Array.prototype.forEach.call(                                                              
                    list,                                                                                  
                    function(element){                                                                     
                        var footerE = element.contentDocument.getElementsByClassName('timeline-footer')[0];
                        footerE.style.backgroundColor="transparent";                                       
                    });                                                                                    
            }                                                                                              
            hideTwitterAttempts++;                                                                         
            if ( hideTwitterAttempts < 3 ) {                                                               
                hideTwitterBoxElements();                                                                  
            }                                                                                              
        }, 1500);                                                                                          
    }                                                                                                      
    hideTwitterBoxElements();                                                                              
    

提交回复
热议问题