Hover over red dot. Mouse press the blue dot. Watch the console events.
Last active
January 4, 2018 18:42
-
-
Save uicoded/466f4bcfa2f6057a2f6678e2ea25f0e8 to your computer and use it in GitHub Desktop.
Events
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 characters
license: mit |
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 characters
<!DOCTYPE html> | |
<head> | |
<meta charset="utf-8"> | |
<script src="https://d3js.org/d3.v3.min.js"></script> | |
<style> | |
body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } | |
.red { | |
fill: red; | |
} | |
.blue { | |
fill: blue; | |
} | |
.orange { | |
fill: orange; | |
} | |
</style> | |
</head> | |
<body> | |
<p><a href="http://blockbuilder.org">Blockbuilder</a></p> | |
<script> | |
// Feel free to change or delete any of the code you see in this editor! | |
var svg = d3.select("body").append("svg") | |
.attr("width", 960) | |
.attr("height", 150) | |
svg.append("circle") | |
.attr("class", "red") | |
.attr("cx", 100) | |
.attr("cy", 75) | |
.attr("r", 20); | |
svg.append("circle") | |
.attr("class", "blue") | |
.attr("cx", 200) | |
.attr("cy", 75) | |
.attr("r", 20); | |
d3.select("circle.red") | |
.on("mouseenter", function (){ | |
console.log("MOUSEENTER", this) | |
}) | |
.on("mouseleave", function (){ | |
console.log("MOUSELEAVE", this) | |
}) | |
d3.select("circle.blue") | |
.on("mousedown", function (){ | |
console.log("MOUSEDOWN", this) | |
}) | |
// use namespace to register multiple handlers | |
// Otherwise the same handler will unregister the previous | |
.on("mousedown.second", function (){ | |
console.log("MOUSEDOWN 2", this) | |
}); | |
d3.select("a") | |
.on("click", function (){ | |
d3.event.preventDefault(); | |
}) | |
// use namespace to register multiple handlers | |
// Otherwise the same handler will unregister the previous | |
.on("click.second", function (){ | |
console.log("CLICKED 2", this); | |
}); | |
</script> | |
</body> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment