Return to Snippet

Revision: 8819
at March 9, 2010 09:40 by wizard04


Updated Code
/****************************************
These functions allow you to easily set a handler for a virtual mouseleave/enter event, using my MouseBoundaryCrossing class.
/****************************************/

//Note that a mouseout/over event is always fired before a mouseleave/enter event
//Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.leftLandmark) handleLeave.call(this, evt);
		}catch(e){}
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.enteredLandmark) handleEnter.call(this, evt);
		}catch(e){}
	}
}

Revision: 8818
at March 9, 2010 09:39 by wizard04


Updated Code
/****************************************
These functions allow you to easily set a handler for a virtual mouseleave/enter event.
/****************************************/

//Note that a mouseout/over event is always fired before a mouseleave/enter event
//Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.leftLandmark) handleLeave.call(this, evt);
		}catch(e){}
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.enteredLandmark) handleEnter.call(this, evt);
		}catch(e){}
	}
}

Revision: 8817
at October 20, 2008 16:22 by wizard04


Updated Code
//Note that a mouseout/over event is always fired before a mouseleave/enter event
//Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.leftLandmark) handleLeave.call(this, evt);
		}catch(e){}
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver.call(this, evt);
		try{
			var mbc = new MouseBoundaryCrossing(evt, this);
			if(mbc.enteredLandmark) handleEnter.call(this, evt);
		}catch(e){}
	}
}

Revision: 8816
at October 20, 2008 15:30 by wizard04


Updated Code
//Note that a mouseout/over event is always fired before a mouseleave/enter event
//Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut.call(this, evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.leftLandmark) handleLeave.call(this, evt);
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver.call(this, evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.enteredLandmark) handleEnter.call(this, evt);
	}
}

Revision: 8815
at October 9, 2008 15:49 by wizard04


Updated Code
//Note that a mouseout/over event is always fired before a mouseleave/enter event
//Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut(evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.leftLandmark) handleLeave(evt);
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver(evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.enteredLandmark) handleEnter(evt);
	}
}

Revision: 8814
at October 9, 2008 15:41 by wizard04


Initial Code
//usage:  elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
//usage:  elem.onmouseover = onMouseEnter(enterHandler, overHandler);
function onMouseLeave(handleLeave, handleOut)
{
	if(!handleLeave) return handleOut;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOut) handleOut(evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.leftLandmark)
		{
			handleLeave(evt);
			//mouseleave event does not bubble, but mouseout does so I can't use evt.stopPropagation()
			//evt.stopPropagation();
		}
	}
}
function onMouseEnter(handleEnter, handleOver)
{
	if(!handleEnter) return handleOver;
	return function(evt)
	{
		evt = evt || window.event;
		if(handleOver) handleOver(evt);
		var mbc = new MouseBoundaryCrossing(evt, this);
		if(mbc.enteredLandmark)
		{
			handleEnter(evt);
			//mouseenter event does not bubble, but mouseover does so I can't use evt.stopPropagation()
			//evt.stopPropagation();
		}
	}
}

Initial URL

                                

Initial Description
These functions allow you to easily set a handler for a virtual mouseleave/enter event.

This requires my [MouseBoundaryCrossing](http://snipplr.com/view/8206/crossbrowser-mouseenterleave-solution/) class.

Initial Title
MouseEnter/Leave Handlers

Initial Tags
javascript, event

Initial Language
JavaScript