javascript:左右两侧广告的滑动特效
1 <html> 2 <head> 3 <title>1</title> 4 <style type='text/css'> 5 #guanggao{ 6 border:solid 1px green; 7 width:120px; 8 height:280px; 9 position:absolute; 10 left:10px; 11 top:200px; 12 background-color:orange; 13 } 14 #guanggao2{ 15 border:solid 1px green; 16 width:120px; 17 height:280px; 18 position:absolute; 19 right:10px; 20 top:200px; 21 background-color:orange; 22 } 23 </style> 24 </head> 25 <body> 26 <div id='guanggao'></div> 27 <div id='guanggao2'></div> 28 <script language='javascript'> 29 for(var i=0;i<200;i++){ 30 document.write('<br/>'); 31 } 32 33 var out; 34 var s; 35 var obj1=document.getElementById('guanggao'); 36 var obj2=document.getElementById('guanggao2'); 37 var top=200; 38 var x; 39 window.onscroll=function(){ 40 window.setTimeout(function(){ 41 out=window.setInterval("move();",30); 42 43 },1000); 44 s=document.body.scrollTop; 45 x=((top+s)-obj1.offsetTop)/15; 46 } 47 function move(){ 48 if(x<0){ 49 if(obj1.offsetTop+x<top+s) 50 obj1.style.top=(top+s)+'px'; 51 else 52 obj1.style.top=(obj1.offsetTop+x)+'px'; 53 }else{ 54 if(obj1.offsetTop+x>top+s) 55 obj1.style.top=(top+s)+'px'; 56 else 57 obj1.style.top=(obj1.offsetTop+x)+'px'; 58 } 59 obj2.style.top=obj1.style.top; 60 //var temp=Number(obj1.style.top.substr(0,obj1.style.top.length-2)); 61 if(obj1.style.top==(top+s)+'px') 62 clearTimeout(out); 63 //6-40.html 64 } 65 </script> 66 </body> 67 </html>