好东西就要收藏起来!
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <title>兼容IE6的淘宝悬浮工具栏</title> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 6 <style type="text/css"> 7 body,html{ 8 margin:0; 9 padding:0; 10 font-size:12px; 11 font-family:Arial;font:12px/1 Helvetica, Tahoma, Arial, 5b8b4f53, sans-serif; 12 background:url() fixed 13 } 14 #float{ 15 background:url(http://www.codefans.net/jscss/demoimg/201010/tb2.png) no-repeat -12px -37px; 16 width:744px; 17 height:34px; 18 border:1px solid #C0DBF8; 19 position:absolute; 20 top:0 21 } 22 #box{ 23 position:relative; 24 height:500px; 25 width:744px; 26 background:#ddd url(http://www.codefans.net/jscss/demoimg/201010/506384_1270823833Kkk2.jpg) no-repeat; 27 } 28 </style> 29 </head> 30 <body> 31 <div style="height:300px;background:#eee"></div> 32 <div id="box"> 33 <div id="float" ></div> 34 </div> 35 <div style="height:1000px;background:#eee"></div> 36 </body> 37 </html> 38 <script type="text/javascript"> 39 var IO=document.getElementById('float'),Y=IO,H=0,IE6; 40 IE6=window.ActiveXObject&&!window.XMLHttpRequest; 41 while(Y){H+=Y.offsetTop;Y=Y.offsetParent}; 42 if(IE6) 43 IO.style.cssText="position:absolute;top:expression(this.fix?(document"+ 44 ".documentElement.scrollTop-(this.javascript||"+H+")):0)"; 45 window.onscroll=function (){ 46 var d=document,s=Math.max(d.documentElement.scrollTop,document.body.scrollTop); 47 if(s>H&&IO.fix||s<=H&&!IO.fix)return; 48 if(!IE6)IO.style.position=IO.fix?"":"fixed"; 49 IO.fix=!IO.fix; 50 }; 51 try{document.execCommand("BackgroundImageCache",false,true)}catch(e){}; 52 //]]> 53 </script>
网上找到的好宝贝~