drop dow
Post on 08-Apr-2018
222 Views
Preview:
TRANSCRIPT
-
8/7/2019 Drop Dow
1/5
//** Chrome Drop Down Menu- Author: Dynamic Drive (http://www.dynamicdrive.com)
//** Updated: July 14th 06' to v2.0//1) Ability to "left", "center", or "right" align the menu items easily
, just by modifying the CSS property "text-align".//2) Added an optional "swipe down" transitional effect for revealing th
e drop down menus.
//3) Support for multiple Chrome menus on the same page.
//** Updated: Nov 14th 06' to v2.01- added iframe shim technique
//** Updated: July 23rd, 08 to v2.4//1) Main menu items now remain "selected" (CSS class "selected" applied
) when user moves mouse into corresponding drop down menu.//2) Adds ability to specify arbitrary HTML that gets added to the end o
f each menu item that carries a drop down menu (ie: a down arrow image).//3) All event handlers added to the menu are now unobstrusive, allowing
you to define your own "onmouseover" or "onclick" events on the menu items.//4) Fixed elusive JS error in FF that sometimes occurs when mouse quick
ly moves between main menu items and drop down menus
//** Updated: Oct 29th, 08 to v2.5 (only .js file modified from v2.4)//1) Added ability to customize reveal animation speed (# of steps)//2) Menu now works in IE8 beta2 (a valid doctype at the top of the page
is required)
var cssdropdown={disappeardelay: 250, //set delay in miliseconds before menu disappears onmouseoutdropdownindicator: '', //specify full HTML to add to end of each menu item with a dropdown menu
enablereveal: [true, 8], //enable swipe effect? [true/false, steps (Number of animation steps. Integer between 1-20. Smaller=faster)]enableiframeshim: 1, //enable "iframe shim" in IE5.5 to IE7? (1=yes, 0=no)
//No need to edit beyond here////////////////////////
dropmenuobj: null, asscmenuitem: null, domsupport: document.all document.getElementById, standardbody: null, iframeshimadded: false, revealtimers: {},
getposOffset:function(what, offsettype){var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;var parentEl=what.offsetParent;
while (parentEl!=null){totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;}return totaloffset;
},
css:function(el, targetclass, action){var needle=new RegExp("(^\\s+)"+targetclass+"($\\s+)", "ig")if (action=="check")
return needle.test(el.className)else if (action=="remove")
el.className=el.className.replace(needle, "")else if (action=="add" && !needle.test(el.className))
el.className+=" "+targetclass
-
8/7/2019 Drop Dow
2/5
},
showmenu:function(dropmenu, e){if (this.enablereveal[0]){
if (!dropmenu._trueheight dropmenu._trueheight
-
8/7/2019 Drop Dow
3/5
return edgeoffset},
dropit:function(obj, e, dropmenuID){if (this.dropmenuobj!=null) //hide previous menu
this.hidemenu() //hide menuthis.clearhidemenu()
this.dropmenuobj=document.getElementById(dropmenuID) //reference drop down menu
this.asscmenuitem=obj //reference associated menu itemthis.showmenu(this.dropmenuobj, e)this.dropmenuobj.x=this.getposOffset(obj, "left")this.dropmenuobj.y=this.getposOffset(obj, "top")this.dropmenuobj.style.left=this.dropmenuobj.x-this.clearbrowseredge(obj
, "rightedge")+"px"this.dropmenuobj.style.top=this.dropmenuobj.y-this.clearbrowseredge(obj,
"bottomedge")+obj.offsetHeight+1+"px"this.positionshim() //call iframe shim function
},
positionshim:function(){ //display iframe shim functionif (this.iframeshimadded){
if (this.dropmenuobj.style.visibility=="visible"){this.shimobject.style.width=this.dropmenuobj.offsetWidth
+"px"this.shimobject.style.height=this.dropmenuobj._trueheigh
t+"px"this.shimobject.style.left=parseInt(this.dropmenuobj.sty
le.left)+"px"this.shimobject.style.top=parseInt(this.dropmenuobj.styl
e.top)+"px"this.shimobject.style.display="block"
}}
},
hideshim:function(){if (this.iframeshimadded)
this.shimobject.style.display='none'},
isContained:function(m, e){var e=window.event evar c=e.relatedTarget ((e.type=="mouseover")? e.fromElement : e.toEle
ment)while (c && c!=m)try {c=c.parentNode} catch(e){c=m}if (c==m)
return trueelse
return false},
dynamichide:function(m, e){if (!this.isContained(m, e)){
this.delayhidemenu()}
},
delayhidemenu:function(){this.delayhide=setTimeout("cssdropdown.hidemenu()", this.disappeardelay)
-
8/7/2019 Drop Dow
4/5
//hide menu},
hidemenu:function(){this.css(this.asscmenuitem, "selected", "remove")this.dropmenuobj.style.visibility='hidden'this.dropmenuobj.style.left=this.dropmenuobj.style.top="-1000px"
this.hideshim()},
clearhidemenu:function(){if (this.delayhide!="undefined")
clearTimeout(this.delayhide)},
addEvent:function(target, functionref, tasktype){if (target.addEventListener)
target.addEventListener(tasktype, functionref, false);else if (target.attachEvent)
target.attachEvent('on'+tasktype, function(){return functionref.call(target, window.event)});},
startchrome:function(){if (!this.domsupport)
returnthis.standardbody=(document.compatMode=="CSS1Compat")? document.document
Element : document.bodyfor (var ids=0; ids
-
8/7/2019 Drop Dow
5/5
}} //end inner for
} //end outer forif (this.enableiframeshim && document.all && !window.XDomainRequest && !
this.iframeshimadded){ //enable iframe shim in IE5.5 thru IE7?document.write('')this.shimobject=document.getElementById("iframeshim") //referenc
e iframe objectthis.shimobject.style.filter='progid:DXImageTransform.Microsoft.
Alpha(style=0,opacity=0)'this.iframeshimadded=true
}} //end startchrome
}
top related