CSS+JS實現點擊文字彈出定時自動關閉DIV層菜單的方法

來源:互聯網
上載者:User

   本文執行個體講述了CSS+JS實現點擊文字彈出定時自動關閉DIV層菜單的方法。分享給大家供大家參考。具體分析如下:

  這裡用CSS+JS實現點擊文字後動畫展開一個DIV層菜單,到期會自動關閉,是CSS結合JS實現的效果。

  ?

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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>CSS+JS彈出DIV層</title> <script type="text/javascript"> var w = 0; var h = 0; var mout; function emotion(){ var oMenu = document.getElementById("menu"); if(w <= 50){ oMenu.style.display = "block"; fnLarge(); } else{ fnSmall(); } } function fnLarge(){ var oMenu = document.getElementById("menu"); if(w < 200){ w += 50; h += 25; oMenu.style.width = w+"px"; oMenu.style.height = h+"px"; window.setTimeout("fnLarge()",10); } } function fnSmall(){ var oMenu = document.getElementById("menu"); if(w > 0){ w -= 50; h -= 25; oMenu.style.width = w+"px"; oMenu.style.height = h+"px"; window.setTimeout("fnSmall()",5); } else{ oMenu.style.display = "none"; } } </script> <style type="text/css"> body{ text-align: center; } p{ cursor: pointer; margin: 0; padding: 0; font-size: 24px; display: inline; } div a:link, div a:visited{ color: #666; text-decoration: none; } div a:hover{ color: #FF6600; text-decoration: underline; } div{ border: 2px solid #666; background: #fff; margin: 5px auto; overflow: hidden; display: none; padding: 5px 10px; } ul,li{ margin: 0; padding: 0; } li{ list-style: none; width:70px; } li.title{ font-weight: bold; } </style> </head> <body> <p onclick="emotion();">點擊這行文字試試!</p> <div id="menu" onmouseout="javascript:mout=setTimeout('fnSmall()',2111);" onMouseOver="javascript:clearTimeout(mout);"> <table border="0" cellspacing="0" cellpadding="0"> <tr> <td width="80" valign="top" align="left"> <ul> <li class="title">ASP</li> <li><a href="#" onclick="fnSmall();">新聞</a></li> <li><a href="#" onclick="fnSmall();">論壇</a></li> <li><a href="#" onclick="fnSmall();">CMS</a></li> <li></li> </ul></td> <td width="80" valign="top" align="left"> <ul> <li class="title">PHP</li> <li><a href="#" onclick="fnSmall();">文章</a></li> <li><a href="#" onclick="fnSmall();">聊天</a></li> <li><a href="#" onclick="fnSmall();">外掛程式</a></li> <li><a href="#" onclick="fnSmall();">企業</a></li> </ul> </td> <td width="80" valign="top" align="left"> <ul> <li class="title">JSP</li> <li><a href="#" onclick="fnSmall();">AJAX</a></li> <li><a href="#" onclick="fnSmall();">JQUERY</a></li> <li><a href="#" onclick="fnSmall();">MYSQL</a></li> <li><a href="#" onclick="fnSmall();">JAVA</a></li> </ul> </td> </tr> </table> </div> </body> </html>

  希望本文所述對大家的javascript程式設計有所協助。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.