Skip to content

Instantly share code, notes, and snippets.

@mwdchang
Created July 12, 2016 19:08
Show Gist options
  • Select an option

  • Save mwdchang/90d8837e1888be87ec09c7ade9e57478 to your computer and use it in GitHub Desktop.

Select an option

Save mwdchang/90d8837e1888be87ec09c7ade9e57478 to your computer and use it in GitHub Desktop.
FF and Chrome absolute element event positions
<!DOCTYPE HTML>
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.js"></script>
<style>
#d1 {
width: 600px;
height: 600px;
background: #CCC;
position: relative;
}
#d2 {
top: 100px;
left: 100px;
width: 200px;
height: 200px;
background: #369;
position: absolute;
}
</style>
</head>
<body id="demo">
<p>x is {{x}} and y is {{y}} </p>
<div id="d1">
<div id="d2">
</div>
</div>
</body>
<script>
var vueData = {
x:0,
y:0
};
var demo = new Vue({
el: '#demo',
data: vueData
});
d3.select('#d2').on('mousemove', function(){
console.log(d3.event);
vueData.x = d3.event.x;
vueData.y = d3.event.y;
});
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment