简体   繁体   English

隐藏内容到dom-load

[英]Hiding content on dom-load

I am making a chrome extension that is supposed to beautify a certain site. 我正在制作一个Chrome扩展程序,该扩展程序应该可以美化某个站点。 I am hiding all elements on domload except one. 我隐藏了domload上的所有元素,除了其中一个。 But the problem with it is that everytime the site loads ,first everything gets loaded, and then it gets hidden. 但是问题在于每次站点加载时,首先加载所有内容,然后隐藏它。 here is my code 这是我的代码

window.onload = function(){

var all = document.getElementsByTagName("div");
var viewer = document.getElementById("viewer").style;

for (var i=0, max=all.length; i < max; i++) {
    all[i].style.visibility='hidden';
}

viewer.visibility='visible';

};

I hope there is a better way of doing this than what I am doing right now, which is basically loading all the content hiding all the content and then making a certain component visible. 我希望有一个比我现在做的更好的方法,它基本上是加载所有内容以隐藏所有内容,然后使某个组件可见。 This whole process is quite slow and the user can see the content I am trying to hide on pageload. 整个过程相当缓慢,用户可以在页面加载中看到我要隐藏的内容。

Is there any way to specify via javascript which content is to be loaded , or to make the whole process fast enough for it to be not noticed ? 有没有办法通过javascript指定要加载的内容,或者使整个过程足够快而不会被注意到?

jQuery here would be your friend. jQuery将成为您的朋友。 It is very fast. 非常快。

$(document).ready(function() {
  $('div').not('#viewer').hide();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM