如何使用Observer使Google Translate横幅响应

时间:2017-04-29 13:04:33

标签: javascript jquery html css mutation-observers

我正试图让谷歌翻译的旗帜响应移动。 但我不能用我的CSS样式修改横幅,所以我使用MutationObserver jsfiddle,但没有成功......任何想法?

// create an observer instance
var target = document.querySelector('body');
console.log(target);
var observer = new WebKitMutationObserver(function(mutations) {
    mutations.forEach(function(mutation) {
    var newNodes = mutation.addedNodes; // DOM NodeList
    if( newNodes !== null ) { // If there are new nodes added
        var $nodes = $( newNodes ); // jQuery set
        $nodes.each(function() {
            var $node = $( this );
            if( $node.hasClass( "goog-te-banner-content" ) ) {
                // do something
             $node.css('color','#ccc');
            }
        });
    }
        console.log(mutation, mutation.type);
    });    
});
observer.observe(target, { attributes: true, childList: true, characterData: true, subtree: true });

0 个答案:

没有答案