Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-29-2012, 12:02 PM   PM User | #1
juneaid
New to the CF scene

 
Join Date: Nov 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
juneaid is an unknown quantity at this point
Question Modification of delaytimer

Hello,

I found jkmegamenu (http://www.javascriptkit.com/script/...megamenu.shtml) beneficial for my website.

As there is a delay time for hiding the menu by default, however I could not succeed for the required modification to set an delay time prior to popup the menu.

I paste the code below and marked the part that I know to set something for the delay for mouse enter, in red.

I need your advice for the modification needed to be able to apply the same delay time prior to pop up the menu.

Thanks.

Code:
jQuery.noConflict();

var jkmegamenu={

effectduration: 0, //duration of animation, in milliseconds
delaytimer: 300, //delay after mouseout before menu should be hidden, in milliseconds

//No need to edit beyond here
megamenulabels: [],
megamenus: [], //array to contain each block menu instances
zIndexVal: 1000, //starting z-index value for drop down menu
jqshimobj: null,

addshim:function(jq){
	jq(document.body).append('<IFRAME id="outlineiframeshim" src="'+(location.protocol=="https:"? 'blank.htm' : 'about:blank')+'" style="display:none; left:0; top:0; z-index:999; position:absolute; filter:progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)" frameBorder="0" scrolling="no"></IFRAME>')
	this.jqshimobj=jq("#outlineiframeshim")
},

alignmenu:function(jq, e, megamenu_pos){
	var megamenu=this.megamenus[megamenu_pos]
	var jqanchor=megamenu.jqanchorobj
	var jqmenu=megamenu.jqmenuobj
	var menuleft=(jq(window).width()-(megamenu.offsetx-jq(document).scrollLeft())>megamenu.actualwidth)? megamenu.offsetx : megamenu.offsetx-megamenu.actualwidth+megamenu.anchorwidth //get x coord of menu
	//var menutop=(jq(window).height()-(megamenu.offsety-jq(document).scrollTop()+megamenu.anchorheight)>megamenu.actualheight)? megamenu.offsety+megamenu.anchorheight : megamenu.offsety-megamenu.actualheight
	var menutop=megamenu.offsety+megamenu.anchorheight  //get y coord of menu
	jqmenu.css({left:265+"px", top:menutop-85+"px"})
	this.jqshimobj.css({width:megamenu.actualwidth+"px", height:megamenu.actualheight+"px", left:menuleft+"px", top:menutop+"px", display:"block"})
},

showmenu:function(e, megamenu_pos){
	var megamenu=this.megamenus[megamenu_pos]
	var jqmenu=megamenu.jqmenuobj
	var jqmenuinner=megamenu.jqmenuinner
	if (jqmenu.css("display")=="none"){
		this.alignmenu(jQuery, e, megamenu_pos)
		jqmenu.css("z-index", ++this.zIndexVal)
		jqmenu.show(this.effectduration, function(){
			jqmenuinner.css('visibility', 'visible')
		})
	}
	else if (jqmenu.css("display")=="block" && e.type=="click"){ //if menu is hidden and this is a "click" event (versus "mouseout")
		this.hidemenu(e, megamenu_pos)
	}
	return false
},

hidemenu:function(e, megamenu_pos){
	var megamenu=this.megamenus[megamenu_pos]
	var jqmenu=megamenu.jqmenuobj
	var jqmenuinner=megamenu.jqmenuinner
	jqmenuinner.css('visibility', 'hidden')
	this.jqshimobj.css({display:"none", left:0, top:0})
	jqmenu.hide(this.effectduration)
},

definemenu:function(anchorid, menuid, revealtype){
	this.megamenulabels.push([anchorid, menuid, revealtype])
},

render:function(jq){
	for (var i=0, labels=this.megamenulabels[i]; i<this.megamenulabels.length; i++, labels=this.megamenulabels[i]){
		if (jq('#'+labels[0]).length!=1 || jq('#'+labels[1]).length!=1) //if one of the two elements are NOT defined, exist
			return
		this.megamenus.push({jqanchorobj:jq("#"+labels[0]), jqmenuobj:jq("#"+labels[1]), jqmenuinner:jq("#"+labels[1]).children('ul:first-child'), revealtype:labels[2], hidetimer:null})
		var megamenu=this.megamenus[i]	
		megamenu.jqanchorobj.add(megamenu.jqmenuobj).attr("_megamenupos", i+"pos") //remember index of this drop down menu
		megamenu.actualwidth=megamenu.jqmenuobj.outerWidth()
		megamenu.actualheight=megamenu.jqmenuobj.outerHeight()
		megamenu.offsetx=megamenu.jqanchorobj.offset().left
		megamenu.offsety=megamenu.jqanchorobj.offset().top
		megamenu.anchorwidth=megamenu.jqanchorobj.outerWidth()
		megamenu.anchorheight=megamenu.jqanchorobj.outerHeight()
		jq(document.body).append(megamenu.jqmenuobj) //move drop down menu to end of document
		megamenu.jqmenuobj.css("z-index", ++this.zIndexVal).hide()
		megamenu.jqmenuinner.css("visibility", "hidden")
		megamenu.jqanchorobj.bind(megamenu.revealtype=="click"? "click" : "mouseenter", function(e){
			var menuinfo=jkmegamenu.megamenus[parseInt(this.getAttribute("_megamenupos"))]
			clearTimeout(menuinfo.hidetimer) //cancel hide menu timer
			return jkmegamenu.showmenu(e, parseInt(this.getAttribute("_megamenupos")))
		})
		megamenu.jqanchorobj.bind("mouseleave", function(e){
			var menuinfo=jkmegamenu.megamenus[parseInt(this.getAttribute("_megamenupos"))]
			if (e.relatedTarget!=menuinfo.jqmenuobj.get(0) && jq(e.relatedTarget).parents("#"+menuinfo.jqmenuobj.get(0).id).length==0){ //check that mouse hasn't moved into menu object
				menuinfo.hidetimer=setTimeout(function(){ //add delay before hiding menu
					jkmegamenu.hidemenu(e, parseInt(menuinfo.jqmenuobj.get(0).getAttribute("_megamenupos")))
				}, jkmegamenu.delaytimer)
			}
		})
		megamenu.jqmenuobj.bind("mouseenter", function(e){
			var menuinfo=jkmegamenu.megamenus[parseInt(this.getAttribute("_megamenupos"))]
			clearTimeout(menuinfo.hidetimer) //cancel hide menu timer
		})
		megamenu.jqmenuobj.bind("click mouseleave", function(e){
			var menuinfo=jkmegamenu.megamenus[parseInt(this.getAttribute("_megamenupos"))]
			menuinfo.hidetimer=setTimeout(function(){ //add delay before hiding menu
				jkmegamenu.hidemenu(e, parseInt(menuinfo.jqmenuobj.get(0).getAttribute("_megamenupos")))
			}, jkmegamenu.delaytimer)
		})
	} //end for loop
	if(/Safari/i.test(navigator.userAgent)){ //if Safari
		jq(window).bind("resize load", function(){
			for (var i=0; i<jkmegamenu.megamenus.length; i++){
				var megamenu=jkmegamenu.megamenus[i]
				var jqanchorisimg=(megamenu.jqanchorobj.children().length==1 && megamenu.jqanchorobj.children().eq(0).is('img'))? megamenu.jqanchorobj.children().eq(0) : null
				if (jqanchorisimg){ //if anchor is an image link, get offsets and dimensions of image itself, instead of parent A
					megamenu.offsetx=jqanchorisimg.offset().left
					megamenu.offsety=jqanchorisimg.offset().top
					megamenu.anchorwidth=jqanchorisimg.width()
					megamenu.anchorheight=jqanchorisimg.height()
				}
			}
		})
	}
	else{
		jq(window).bind("resize", function(){
			for (var i=0; i<jkmegamenu.megamenus.length; i++){
				var megamenu=jkmegamenu.megamenus[i]	
				megamenu.offsetx=megamenu.jqanchorobj.offset().left
				megamenu.offsety=megamenu.jqanchorobj.offset().top
			}
		})
	}
	jkmegamenu.addshim(jq)
}

}

jQuery(document).ready(function(jq){
	jkmegamenu.render(jq)
})
juneaid is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:46 PM.


Advertisement
Log in to turn off these ads.