Discuz!官方免费开源建站系统

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索

[hack]另一种下拉菜单.

[复制链接]
hufanyun 发表于 2005-9-5 00:48:33 | 显示全部楼层 |阅读模式
打开CSS.htm加入:
  1. <style type="text/css">
  2. .anylinkcss{
  3. position:absolute;
  4. visibility: hidden;
  5. border:1px solid black;
  6. border-bottom-width: 0;
  7. font:normal 12px Verdana;
  8. line-height: 18px;
  9. z-index: 100;
  10. background-color: #E9FECB;
  11. width: 205px;
  12. }

  13. .anylinkcss a{
  14. width: 100%;
  15. display: block;
  16. text-indent: 3px;
  17. border-bottom: 1px solid black;
  18. padding: 1px 0;
  19. text-decoration: none;
  20. font-weight: bold;
  21. text-indent: 5px;
  22. }

  23. .anylinkcss a:hover{ /*hover background color*/
  24. background-color: black;
  25. color: white;
  26. }

  27. </style>
  28. <script language="javascript">
  29. //more javascript from http://www.smallrain.net
  30. var disappeardelay=250  //menu disappear speed onMouseout (in miliseconds)
  31. var enableanchorlink=0 //Enable or disable the anchor link when clicked on? (1=e, 0=d)
  32. var hidemenu_onclick=1 //hide menu when user clicks within menu? (1=yes, 0=no)

  33. /////No further editting needed

  34. var ie5=document.all
  35. var ns6=document.getElementById&&!document.all

  36. function getposOffset(what, offsettype){
  37. var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  38. var parentEl=what.offsetParent;
  39. while (parentEl!=null){
  40. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
  41. parentEl=parentEl.offsetParent;
  42. }
  43. return totaloffset;
  44. }

  45. function showhide(obj, e, visible, hidden){
  46. if (ie5||ns6)
  47. dropmenuobj.style.left=dropmenuobj.style.top=-500
  48. if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
  49. obj.visibility=visible
  50. else if (e.type=="click")
  51. obj.visibility=hidden
  52. }

  53. function iecompattest(){
  54. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  55. }

  56. function clearbrowseredge(obj, whichedge){
  57. var edgeoffset=0
  58. if (whichedge=="rightedge"){
  59. var windowedge=ie5 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
  60. dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
  61. if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
  62. edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
  63. }
  64. else{
  65. var windowedge=ie5 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  66. dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
  67. if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure)
  68. edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
  69. }
  70. return edgeoffset
  71. }

  72. function dropdownmenu(obj, e, dropmenuID){
  73. if (window.event) event.cancelBubble=true
  74. else if (e.stopPropagation) e.stopPropagation()
  75. if (typeof dropmenuobj!="undefined") //hide previous menu
  76. dropmenuobj.style.visibility="hidden"
  77. clearhidemenu()
  78. if (ie5||ns6){
  79. obj.onmouseout=delayhidemenu
  80. dropmenuobj=document.getElementById(dropmenuID)
  81. if (hidemenu_onclick) dropmenuobj.onclick=function(){dropmenuobj.style.visibility='hidden'}
  82. dropmenuobj.onmouseover=clearhidemenu
  83. dropmenuobj.onmouseout=ie5? function(){ dynamichide(event)} : function(event){ dynamichide(event)}
  84. showhide(dropmenuobj.style, e, "visible", "hidden")
  85. dropmenuobj.x=getposOffset(obj, "left")
  86. dropmenuobj.y=getposOffset(obj, "top")
  87. dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
  88. dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
  89. }
  90. return clickreturnvalue()
  91. }

  92. function clickreturnvalue(){
  93. if ((ie5||ns6) && !enableanchorlink) return false
  94. else return true
  95. }

  96. function contains_ns6(a, b) {
  97. while (b.parentNode)
  98. if ((b = b.parentNode) == a)
  99. return true;
  100. return false;
  101. }

  102. function dynamichide(e){
  103. if (ie5&&!dropmenuobj.contains(e.toElement))
  104. delayhidemenu()
  105. else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
  106. delayhidemenu()
  107. }

  108. function delayhidemenu(){
  109. delayhide=setTimeout("dropmenuobj.style.visibility='hidden'",disappeardelay)
  110. }

  111. function clearhidemenu(){
  112. if (typeof delayhide!="undefined")
  113. clearTimeout(delayhide)
  114. }
  115. </script>
复制代码

在header.htm合适的地方加:
  1. <!--第一个链接和菜单 -->
  2. <a href="https://discuz.dismall.com/javascript" onClick="return clickreturnvalue()" onMouseover="dropdownmenu(this, event, 'anylinkmenu1')">下拉显示</a>   
  3.                                                    
  4. <div id="anylinkmenu1" class="anylinkcss">

  5. <a href="地址一">名称一</a>
  6. <a href="地址二">名称二</a>
  7. <a href="地址三">名称三</a>

  8. </div>
复制代码

表格的颜色的宽度可以自己调节.

演示:
http://free3.e-168.cn/tongxue79/index.php

[ 本帖最后由 hufanyun 于 2005-9-5 00:51 编辑 ]
freddy 发表于 2005-9-5 00:50:32 | 显示全部楼层
沙发!
回复

使用道具 举报

freddy 发表于 2005-9-5 00:52:04 | 显示全部楼层
爽!!!
回复

使用道具 举报

 楼主| hufanyun 发表于 2005-9-5 00:52:31 | 显示全部楼层
这个连下拉显示都可以有连接,简单吧
回复

使用道具 举报

 楼主| hufanyun 发表于 2005-9-5 01:00:21 | 显示全部楼层
不知道有没有人喜欢DZ官方www.discuz.com那种象图片一样的渐显下拉菜单
回复

使用道具 举报

爱雨冷雪 发表于 2005-9-5 02:29:28 | 显示全部楼层
看不到呀?
回复

使用道具 举报

tomsina 发表于 2005-9-5 03:44:39 | 显示全部楼层
演示有下拉?
回复

使用道具 举报

 楼主| hufanyun 发表于 2005-9-5 09:13:51 | 显示全部楼层
演示删除了.因为我正在制作DZ官方的下拉菜单
回复

使用道具 举报

freddy 发表于 2005-9-5 09:26:02 | 显示全部楼层
原帖由 hufanyun 于 2005-9-5 01:00 发表
不知道有没有人喜欢DZ官方www.discuz.com那种象图片一样的渐显下拉菜单


我喜欢的,我要的!期待兄弟的作品!
回复

使用道具 举报

beecheung 发表于 2005-9-5 09:35:28 | 显示全部楼层
支持,,,,顶一下, 快出来.
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|Discuz! 官方站 ( 皖ICP备16010102号 )star

GMT+8, 2024-5-21 19:42 , Processed in 0.109512 second(s), 17 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表