-: onload div. :, , , !
-, URL- ( ): url('http://lamininbeauty.co.za/images/products/facial.jpg')
-, preloader.gif, loader.gif, css jsfiddle .
SO-server-move , , .
IE6 FF12.
: , ( ), , , ( , )!
JavaScript:
var repBg=function(a, t){ t=t||'*';
var c=document.getElementsByTagName(t), i=c.length, r=[];
while(i--){if (c[i].getAttribute(a)){r.push(c[i]);}} c=r; i=c.length;
repBg.exec=function(){
c[this['data-i']].style.background="#ebebeb url('"+this.src+"') no-repeat top right";
};
while(i--){ if (c[i].getAttribute(a)) {
r=new Image();
r.onload=repBg.exec;
r['data-i']=i;
r.src=c[i].getAttribute(a);
}}
};
: 'data-bg_img' ( html5, ), , , url, :
<div id="glykopeels" data-bg_img="http://lamininbeauty.co.za/images/products/glykopeel.jpg">Glykopeels Content</div>
"" :
<img src="http://lamininbeauty.co.za/images/products/loader.gif" style="display:none;" onload="this.onload=null; repBg('data-bg_img','div');">
/:
onload-, html (), onload-, repBg(), !!!
repBg() 2 :
repBg() elementTagNames, *, .
htmlObject, htmlObjectCollection, ( ) - htmlObject (url), , htmlObjectCollection ( data-id) .
, onload: repBg exec, htmlObject () ( css). .
, : , , , , .
: http://jsfiddle.net/epdDa/
2: GRACEFUL FALLBACK!! NOBRAIN
, . , .
IE6 FF12
:
: SIMPLY div "preload" , . :
<div id="facials" class="preload" style="background: #ebebeb url('http://lamininbeauty.co.za/images/products/facial.jpg') no-repeat top right;">Facials Content</div>
?
script HEAD ( ) HTML:
document.getElementsByClassName=document.getElementsByClassName||function(searchClass,node,tag) {
var classElements = [], i=0, j=0;
if (!node){node = document;}
if (!tag){tag = '*';}
var els = node.getElementsByTagName(tag);
var elsLen = els.length;
var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
for (; i < elsLen; i++) {
if ( pattern.test(els[i].className) ) {
classElements[j] = els[i]; j++;}
} return classElements;
};
var repBg=(function(n,u,p,a,i,r){
window.onload=function(){repBg(1);};
i=new Image(); i.onload=function(){this.onload=null; repBg(2);};
document.write("<style>."+n+"{background:"+p+" url("+u+") "+a+
" !important; background-size: contain !important;}"+
"</style>");
i.src=u; r=0;
return function(t){
r=r+t; if(r>2){
var c=document.getElementsByClassName(n), i=0, l=c.length, s;
repBg.exec=function(){
document.getElementById(this['data-id']).className='';
};
for(;i<l;i++){
r=new Image();
r.onload=repBg.exec;
r['data-id']=c[i].getAttribute('id');
s=c[i].getAttribute('style');
try {
r.src=s.match(/url\('?([^'"]*)'?\)/i)[1];
} catch(e) {
r.src=s.cssText.match(/url\('?([^'"]*)'?\)/i)[1];
}
}
}
};
})('preload','http://lamininbeauty.co.za/images/products/loader.gif','#ebebeb','no-repeat top right');
:
... .
javascript , repBg (, , , css script)), -- ( pageload).
( ), 1. URL- style-atribute onload style .
, 1 ( ), "repBg".
: sate repBg 4 : className, Url, cssPrepend cssAppend.
( , ),
: http://jsfiddle.net/epdDa/1/
, , !
UPDATE:
.
, .
- 1 javascript - , , xhtml html.
, , JavaScript, ( gifs). , , , , ! - 2 javascript - , ( -), html ( xhtml).
, javascript . IE: javascript . " " " ". 1 2.
:. SEMANTIC html, , id . 2 2
css? "" css ?
, , css. ( , , , ). , , , , URL- , css, css div , -, . 2 .
css HEAD - .
css..??
, / , : css . , , pageload, , . preload? : css , , ( ). .
, (true) xhtml-, document.write, , ( ). - css. (KISS-) 2.
2 , : repBg exec (= ) 'upgradeed', preload valuelist. () ( ).
2 , - , "".
, : , 2 : onload- , ( css ), : , , . . ... css: bam! , " ". . , pageload. , . -.
!
(, , , / /, !)