Posted By

wizard04 on 10/09/08


Tagged

javascript event mouse mouseenter mouseleave


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

jsluv


MouseEnter/Leave Handlers


 / Published in: JavaScript
 

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

This requires my MouseBoundaryCrossing class.

  1. /****************************************
  2. These functions allow you to easily set a handler for a virtual mouseleave/enter event, using my MouseBoundaryCrossing class.
  3. /****************************************/
  4.  
  5. //Note that a mouseout/over event is always fired before a mouseleave/enter event
  6. //Also note that mouseleave/enter events do not bubble; effectively, they don't bubble in this implementation either.
  7. //usage: elem.onmouseout = onMouseLeave(leaveHandler, outHandler);
  8. //usage: elem.onmouseover = onMouseEnter(enterHandler, overHandler);
  9. function onMouseLeave(handleLeave, handleOut)
  10. {
  11. if(!handleLeave) return handleOut;
  12. return function(evt)
  13. {
  14. evt = evt || window.event;
  15. if(handleOut) handleOut.call(this, evt);
  16. try{
  17. var mbc = new MouseBoundaryCrossing(evt, this);
  18. if(mbc.leftLandmark) handleLeave.call(this, evt);
  19. }catch(e){}
  20. }
  21. }
  22. function onMouseEnter(handleEnter, handleOver)
  23. {
  24. if(!handleEnter) return handleOver;
  25. return function(evt)
  26. {
  27. evt = evt || window.event;
  28. if(handleOver) handleOver.call(this, evt);
  29. try{
  30. var mbc = new MouseBoundaryCrossing(evt, this);
  31. if(mbc.enteredLandmark) handleEnter.call(this, evt);
  32. }catch(e){}
  33. }
  34. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: wizard04 on April 16, 2014

The latest: https://github.com/wizard04wsu/Events_Max

You need to login to post a comment.