
延时框的使用经常是用于导航栏的使用,下面是一个简单例子:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
|
<html> <head> <title></title> <style> div{ float:left; margin:10px; } width:50px; height:50px; background:red; } width:250px; height:250px; background:gray; display:none; } </style> <script> window.onload=(){ var oDiv1=document.getElementById('div1'); var oDiv2=document.getElementById('div2'); var timer=null; oDiv1.onmouseover=(){ oDiv2.style.display='block'; }; oDiv1.onmouseout=(){ timer=setTimeout((){ oDiv2.style.display='none'; },500); }; oDiv2.onmouseover=(){ clearTimeout(timer); } } </script> </head> <body> <div id="div1"></div> <div id="div2"></div> </body> </html>
|
近期评论