Forked from toruta39/preventAdditionalMouseEvent.html
Created
April 15, 2023 12:02
-
-
Save kongondo/4e64b4e9f1e53c855bba26b984e81dfc to your computer and use it in GitHub Desktop.
Revisions
-
toruta39 revised this gist
Jul 17, 2012 . 2 changed files with 21 additions and 5 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -7,9 +7,12 @@ <body> <div id="ele" style="width: 300px; height: 300px; background-color: #0FF;"> This is the parent element. <div style="width: 200px; height: 200px; background-color: #FFF;"> This is the child element. <div style="width: 150px; background-color: #000; color: #FFF"> Grand child element. </div> </div> </div> <script type="text/javascript" src="preventAdditionalMouseEvent.js"></script> </body> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,10 +2,23 @@ var ele = document.getElementById("ele"); var over = 0, out = 0; //Detect if otherNode is contained by refNode function isParent(refNode, otherNode) { var parent = otherNode.parentNode; do { if (refNode == parent) { return true; } else { parent = parent.parentNode; } } while (parent); return false; } ele.addEventListener("mouseover", function(ev){ //Make sure that the mouseover event isn't triggered when moving from a child element //or bubbled from a child element if (!isParent(this, ev.relatedTarget) && ev.target == this){ //Event handling code here this.style.backgroundColor = "#FF0"; this.childNodes[0].nodeValue = "Mouseover: " + ++over +", Mouseout: " + out + "."; @@ -15,7 +28,7 @@ ele.addEventListener("mouseover", function(ev){ ele.addEventListener("mouseout", function(ev){ //Make sure that the mouseout event is triggered when moving onto a child element //or bubbled from a child element if (!isParent(this, ev.relatedTarget) && ev.target == this){ //Event handling code here this.style.backgroundColor = "#0FF"; this.childNodes[0].nodeValue = "Mouseover: " + over +", Mouseout: " + ++out + "."; -
toruta39 revised this gist
Jul 17, 2012 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,8 @@ var ele = document.getElementById("ele"); var over = 0, out = 0; ele.addEventListener("mouseover", function(ev){ //Make sure that the mouseover event isn't triggered when moving from a child element //or bubbled from a child element if (ev.relatedTarget.parentNode != this && ev.target == this){ //Event handling code here this.style.backgroundColor = "#FF0"; @@ -12,7 +13,8 @@ ele.addEventListener("mouseover", function(ev){ }, false); ele.addEventListener("mouseout", function(ev){ //Make sure that the mouseout event is triggered when moving onto a child element //or bubbled from a child element if (ev.relatedTarget.parentNode != this && ev.target == this){ //Event handling code here this.style.backgroundColor = "#0FF"; -
toruta39 revised this gist
Jul 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,7 +12,7 @@ ele.addEventListener("mouseover", function(ev){ }, false); ele.addEventListener("mouseout", function(ev){ //Make sure that the mouseout event isn't triggered when moving onto a child element if (ev.relatedTarget.parentNode != this && ev.target == this){ //Event handling code here this.style.backgroundColor = "#0FF"; -
toruta39 revised this gist
Jul 17, 2012 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ <!DOCTYPE html> <html lang="en-US"> <head> <meta charset="UTF-8"> <title>Prevent additional mouse event</title> </head> <body> -
toruta39 created this gist
Jul 17, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ <!DOCTYPE html> <html lang="en-US"> <head> <meta charset = "UTF-8"> <title>Prevent additional mouse event</title> </head> <body> <div id="ele" style="width: 300px; height: 300px; background-color: #0FF;"> This is the parent element. <p style="width: 200px; height: 50px; background-color: #FFF;"> And this is the child element. </p> </div> <script type="text/javascript" src="preventAdditionalMouseEvent.js"></script> </body> </html> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ var ele = document.getElementById("ele"); var over = 0, out = 0; ele.addEventListener("mouseover", function(ev){ //Make sure that the mouseover event isn't bubbled from a child element if (ev.relatedTarget.parentNode != this && ev.target == this){ //Event handling code here this.style.backgroundColor = "#FF0"; this.childNodes[0].nodeValue = "Mouseover: " + ++over +", Mouseout: " + out + "."; } }, false); ele.addEventListener("mouseout", function(ev){ //Make sure that the mouseout event is triggered when moving onto a child element if (ev.relatedTarget.parentNode != this && ev.target == this){ //Event handling code here this.style.backgroundColor = "#0FF"; this.childNodes[0].nodeValue = "Mouseover: " + over +", Mouseout: " + ++out + "."; } }, false);