D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
ezzaouia
Full window
Github gist
div drag
Built with
blockbuilder.org
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> <style> #div { font-size: 10px; border-radius: 3px; box-shadow: 0 0 5px #999; padding: 10px; pointer-events: 'none'; background-color: #fff; position: absolute; } body { margin:0;position:fixed;top:0;right:0;bottom:0;left:0; } </style> </head> <body> <video id="div" width="350"> <source src="" type="video/webm"> </video> </div> <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", 500) let div = d3.select('#div') .call(d3.drag() .on('start.interrupt', function () { div.interrupt(); console.log('stop') }) .on('start drag', function () { console.log('drag') div.style('top', d3.event.y + 'px') div.style('left', d3.event.x + 'px') })); </script> </body>
https://d3js.org/d3.v4.min.js