Determines whether the mouse is in the specified area code

Source: Internet
Author: User

<div style= "width:300px; height:300px; border:1px solid red; " > <div id= "target" ><div><span> test </span></div></div></div>
<style type= "Text/css" > #target {width:200px; height:200px; background: #EEE;} #target div{width:150px; height:150px; border:1px solid Orange;} #target span{display:block; width:50px; height:50px; background:gray;} </style>
var target = document.getElementById (' target '), if (Target.addeventlistener) {Target.addeventlistener ("mouseout", Mouseouthander,false)}else if (target.attachevent) {target.attachevent ("onmouseout", Mouseouthander);} Else{target.onmouseout = Mouseouthander;} function Mouseouthander (e) {e = e | | Window.event;var target = e.target | | e.srcelement;  Determines whether the element that is moved out of the mouse is the target element  if (target.id!== ' target ') {    return;  }  Determines whether the mouse is moved out of the element or moved to a child element  var relatedtarget = E.relatedtarget | | e.toelement;  while (relatedtarget!== target    && relatedTarget.nodeName.toUpperCase ()!== ' BODY ') {    relatedtarget = Relatedtarget.parentnode;  }  If equal, indicates that the mouse moves inside the element if  (Relatedtarget = = = target) {    return;  }  Execution requires action  alert (' Mouse Out ');}

Execute the above code, the mouse moves in the specified area will not always pop up the warning box

Determines whether the mouse is in the specified area code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.