Skip to content

Instantly share code, notes, and snippets.

@delenamalan
Last active August 12, 2019 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delenamalan/3ad7c010763e32d4e22a81556a01a4e3 to your computer and use it in GitHub Desktop.
Save delenamalan/3ad7c010763e32d4e22a81556a01a4e3 to your computer and use it in GitHub Desktop.
Mouseout demo
license: gpl-3.0
<!DOCTYPE html>
<meta charset="utf-8">
<style>
.fill {
fill: #ccc;
}
.stroke {
fill: none;
stroke: #000;
stroke-width: 20px;
}
</style>
<svg width="400" height="400">
</svg>
<script src="//d3js.org/d3.v3.min.js"></script>
<script>
var svg = d3.select("svg");
var text = svg.append("text").attr({ x: 50, y: 50})
.text("test");
var drag = d3.behavior.drag()
.on("dragstart", function() {
text.text("dragstart");
console.log("dragstart");
})
.on("drag", function() {
text.text("drag");
console.log("drag");
d3.select(this)
.attr("cx", d3.event.x)
.attr("cy", d3.event.y);
d3.select(this).style("fill", "red");
})
.on("dragend", function() {
text.text("dragend");
console.log("dragend");
d3.select(this)
.attr("cx", 200)
.attr("cy", 200);
d3.select(this).style("fill", "#3BA360");
// See if manually triggering "mousemove" would work.
// d3.select(document).on("mousemove")();
});
svg.append("circle")
.attr({
r: 100,
cx: 200,
cy: 200,
fill: "#3BA360"
})
.style("stroke-width", 3)
.on("mouseover", function () {
text.text("mouseover");
console.log("mouseover");
d3.select(this).style("stroke", "#000");
})
.on("mousemove", function () {
text.text("mousemove");
console.log("mousemove");
})
.on("mouseout", function () {
text.text("mouseout");
console.log("mouseout");
d3.select(this).style("stroke", "none");
})
.call(drag)
;
d3.select(document).on("mousemove", function() {
// console.log("mousemove");
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment