Published in: JavaScript
- Adjustable delay until menu appears to prevent accidental activation
- Snipped out of production sources, needs some generalization.
- http://alexle.net/archives/169
- http://www.klevo.sk/javascript/javascripts-settimeout-and-how-to-use-it-with-your-methods/
- http://www.tomanthony.co.uk/demo/delayedCSSmenu/
// attach events to all menu items function addHooks() { var menuLinks = document.getElementById('head_nav1').getElementsByTagName('a'); for(var i = 0; i < menuLinks.length; i++) { addEvent(menuLinks[i], "mouseover", activateMenuWithDelay); addEvent(menuLinks[i], "mouseout", deactivateMenu); } } // helper for addHooks(), needed for different browser behaviour function addEvent (elm, type, fnc) { if (window.addEventListener) { elm.addEventListener(type, fnc, false); } // IE else { elm.attachEvent("on" + type, fnc); } } function activateMenuWithDelay() { var oThis = this; var ident; // IE & Opera if (window.event) { srcElm = window.event.srcElement; ident = srcElm.attributes["ident"].value; oThis = srcElm; } // W3C DOM (FF, Mozilla, Safari) else { ident = this.attributes["ident"].value; } if(oThis.timer) { clearTimeout(oThis.timer); } oThis.timer = setTimeout(function() { displaySubMenu.apply(oThis, [ident,oThis]); }, 130); } function deactivateMenu() { var oThis = this; // IE & Opera if (window.event) { oThis = window.event.srcElement; } if(oThis.timer) { clearTimeout(oThis.timer); } }
You need to login to post a comment.
