我按照智能社的教程制做了一个悬浮框,但是除了ie6/7,其他浏览器中色块都显示不全。只有把控制速度的分母去掉才行,但是那是控制快慢的,而且教程里也有分母。我把代码贴上来,大家帮我看看是哪儿出了问题。
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 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>悬浮框</title> 6 <style type="text/css"> 7 #fix { 8 background-color: red; 9 height: 150px; 10 width: 100px; 11 position: absolute; 12 right: 0; 13 bottom: 0; 14 } 15 </style> 16 <script type="text/javascript"> 17 var timerFix=null; 18 19 function moveFix(iTarget){ 20 var oPFix=document.getElementById('fix'); 21 22 clearInterval(timerFix); 23 timerFix=setInterval(function(){ 24 var speed=(iTarget-oPFix.offsetTop)/5; 25 speed=speed>0?Math.ceil(speed):Math.floor(speed); 26 27 if(oPFix.offsetTop==iTarget){ 28 clearInterval(timerFix); 29 } 30 else{ 31 oPFix.style.top=oPFix.offsetTop+speed+'px'; 32 } 33 },30); 34 } 35 36 window.onscroll=function(){ 37 var oPFix=document.getElementById('fix'); 38 var scrollTop=document.documentElement.scrollTop || document.body.scrollTop; 39 //oPFix.style.top=document.documentElement.clientHeight-oPFix.offsetHeight+scrollTop+'px'; 40 moveFix(document.documentElement.clientHeight-oPFix.offsetHeight+scrollTop); 41 }; 42 </script> 43 44 </head> 45 46 <body style="height:2000px;"> 47 <p id="fix"></p> 48 </body> 49 </html>