国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.4KB

  1. var cssdropdown={
  2. disappeardelay: 250,
  3. disablemenuclick: false,
  4. enableswipe: 1,
  5. enableiframeshim: 1,
  6. dropmenuobj: null, ie: document.all, firefox: document.getElementById&&!document.all, swipetimer: undefined, bottomclip:0,
  7. getposOffset:function(what, offsettype){
  8. var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
  9. var parentEl=what.offsetParent;
  10. while (parentEl!=null){
  11. totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
  12. parentEl=parentEl.offsetParent;
  13. }
  14. return totaloffset;
  15. },
  16. swipeeffect:function(){
  17. if (this.bottomclip<parseInt(this.dropmenuobj.offsetHeight)){
  18. this.bottomclip+=10+(this.bottomclip/10)
  19. this.dropmenuobj.style.clip="rect(0 auto "+this.bottomclip+"px 0)"
  20. }
  21. else
  22. return
  23. this.swipetimer=setTimeout("cssdropdown.swipeeffect()", 10)
  24. },
  25. showhide:function(obj, e){
  26. if (this.ie || this.firefox)
  27. this.dropmenuobj.style.left=this.dropmenuobj.style.top="-500px"
  28. if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover"){
  29. if (this.enableswipe==1){
  30. if (typeof this.swipetimer!="undefined")
  31. clearTimeout(this.swipetimer)
  32. obj.clip="rect(0 auto 0 0)"
  33. this.bottomclip=0
  34. this.swipeeffect()
  35. }
  36. obj.visibility="visible"
  37. }
  38. else if (e.type=="click")
  39. obj.visibility="hidden"
  40. },
  41. iecompattest:function(){
  42. return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
  43. },
  44. clearbrowseredge:function(obj, whichedge){
  45. var edgeoffset=0
  46. if (whichedge=="rightedge"){
  47. var windowedge=this.ie && !window.opera? this.iecompattest().scrollLeft+this.iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
  48. this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetWidth
  49. if (windowedge-this.dropmenuobj.x < this.dropmenuobj.contentmeasure)
  50. edgeoffset=this.dropmenuobj.contentmeasure-obj.offsetWidth
  51. }
  52. else{
  53. var topedge=this.ie && !window.opera? this.iecompattest().scrollTop : window.pageYOffset
  54. var windowedge=this.ie && !window.opera? this.iecompattest().scrollTop+this.iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
  55. this.dropmenuobj.contentmeasure=this.dropmenuobj.offsetHeight
  56. if (windowedge-this.dropmenuobj.y < this.dropmenuobj.contentmeasure){
  57. edgeoffset=this.dropmenuobj.contentmeasure+obj.offsetHeight
  58. if ((this.dropmenuobj.y-topedge)<this.dropmenuobj.contentmeasure)
  59. edgeoffset=this.dropmenuobj.y+obj.offsetHeight-topedge
  60. }
  61. }
  62. return edgeoffset
  63. },
  64. dropit:function(obj, e, dropmenuID){
  65. if (this.dropmenuobj!=null)
  66. this.dropmenuobj.style.visibility="hidden"
  67. this.clearhidemenu()
  68. if (this.ie||this.firefox){
  69. obj.onmouseout=function(){cssdropdown.delayhidemenu()}
  70. obj.onclick=function(){return !cssdropdown.disablemenuclick}
  71. this.dropmenuobj=document.getElementById(dropmenuID)
  72. if(!this.dropmenuobj) return;
  73. this.dropmenuobj.onmouseover=function(){cssdropdown.clearhidemenu()}
  74. this.dropmenuobj.onmouseout=function(e){cssdropdown.dynamichide(e)}
  75. this.dropmenuobj.onclick=function(){cssdropdown.delayhidemenu()}
  76. this.showhide(this.dropmenuobj.style, e)
  77. this.dropmenuobj.x=this.getposOffset(obj, "left")
  78. this.dropmenuobj.y=this.getposOffset(obj, "top")
  79. this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj, "rightedge")+"px"
  80. this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+1+"px"
  81. this.positionshim()
  82. }
  83. },
  84. positionshim:function(){
  85. if (this.enableiframeshim && typeof this.shimobject!="undefined"){
  86. if (this.dropmenuobj.style.visibility=="visible"){
  87. this.shimobject.style.width=this.dropmenuobj.offsetWidth+"px"
  88. this.shimobject.style.height=this.dropmenuobj.offsetHeight+"px"
  89. this.shimobject.style.left=this.dropmenuobj.style.left
  90. this.shimobject.style.top=this.dropmenuobj.style.top
  91. }
  92. this.shimobject.style.display=(this.dropmenuobj.style.visibility=="visible")? "block" : "none"
  93. }
  94. },
  95. hideshim:function(){
  96. if (this.enableiframeshim && typeof this.shimobject!="undefined")
  97. this.shimobject.style.display='none'
  98. },
  99. contains_firefox:function(a, b) {
  100. while (b.parentNode)
  101. if ((b = b.parentNode) == a)
  102. return true;
  103. return false;
  104. },
  105. dynamichide:function(e){
  106. var evtobj=window.event? window.event : e
  107. if (this.ie&&!this.dropmenuobj.contains(evtobj.toElement))
  108. this.delayhidemenu()
  109. else if (this.firefox&&e.currentTarget!= evtobj.relatedTarget&& !this.contains_firefox(evtobj.currentTarget, evtobj.relatedTarget))
  110. this.delayhidemenu()
  111. },
  112. delayhidemenu:function(){
  113. this.delayhide=setTimeout("cssdropdown.dropmenuobj.style.visibility='hidden'; cssdropdown.hideshim()",this.disappeardelay)
  114. },
  115. clearhidemenu:function(){
  116. if (this.delayhide!="undefined")
  117. clearTimeout(this.delayhide)
  118. },
  119. startchrome:function(){
  120. for (var ids=0; ids<arguments.length; ids++){
  121. var menuitems=document.getElementById(arguments[ids]).getElementsByTagName("a")
  122. for (var i=0; i<menuitems.length; i++){
  123. if (menuitems[i].getAttribute("rel")){
  124. var relvalue=menuitems[i].getAttribute("rel")
  125. menuitems[i].onmouseover=function(e){
  126. var event=typeof e!="undefined"? e : window.event
  127. cssdropdown.dropit(this,event,this.getAttribute("rel"))
  128. }
  129. }
  130. }
  131. }
  132. if (window.createPopup && !window.XmlHttpRequest){
  133. document.write('<IFRAME id="iframeshim" src="" style="display: none; left: 0; top: 0; z-index: 90; position: absolute; filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"></IFRAME>')
  134. this.shimobject=document.getElementById("iframeshim")
  135. }
  136. }
  137. }