JS伸缩效果
- 发表于
- jQuery
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" " http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Untitled Document</title> </head> <body> <style> .b{ position:absolute; top:130px; left:250px; height:100px; background-color:#666; } </style> <div class="b" id="layout" style="width:30px;" onmouseover="showdiv('layout')" onmouseout="closediv('layout')" > <table> <tr> <td>111</td> </tr> </table> </div> <script> var a2,a1; var dir = 0; function showdiv(id){ if(a2){ clearInterval(a2); } var obj = document.getElementById(id); obj.style.display = "block"; var changw = function(){ var obj_w = parseInt(obj.style.width); if(obj_w<=300){ obj.style.width = obj_w + Math.ceil((300-obj_w)/10) + "px"; } else{ if(a1){ clearInterval(a1); } } } a1 = setInterval(changw,10); if(dir>0){ clearInterval(a2); } } function closediv(id){ if(a1){ clearInterval(a1); } dir ++; var obj = document.getElementById(id); var closed = function(){ var obj_w = parseInt(obj.style.width); clearInterval(a1); if(obj_w>30){ obj.style.width = obj_w - Math.ceil(obj_w/10) +"px"; } else{ if(a2){ clearInterval(a2); } } } a2 = setInterval(closed,1); } function stopdiv(){ clearInterval(a1); clearInterval(a2); obj.style.width = "300px"; } </script> </body> </html> |