JavaScript MouseEnter / Leave处理程序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript MouseEnter / Leave处理程序相关的知识,希望对你有一定的参考价值。

/****************************************
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){}
	}
}

以上是关于JavaScript MouseEnter / Leave处理程序的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript 跨浏览器MouseEnter / Leave解决方案

javascript----mouseover和mouseenter的区别

JavaScript里mouseenter和mouseleave与mouseover和mouseout的区别

没有 JQuery 的 mouseenter

Mouseenter 委托问题 vanilla js

03JavaScript程序设计修炼之道_2019-07-02_21-47-36_ 鼠标弹起拖拽放大镜mouseenter&mouseleave