Are there any examples of a drag-and-drop solution in which the elements being dragged can only move along a slanted line? For example, constrain an element's draggability so that it can only be moved along a 30º line, or 10º, etc.
Most examples I've been able to find only constrain the dragged element's area to either a vertical or horizontal line, or to within a larger parent div.
Possibly related: Drag along a diagonal line no further than 100px, or along a curve.
complete example (FF only)
<div id="drag" style="position:absolute;width:20px;height:20px;background:red"></div>
<script>
var angle = 10;
window.onload = function()
{
var d = document.getElementById("drag");
d.onmousedown = function() {
document.onmouseup = function() {
document.onmousemove = null;
}
document.onmousemove = function(e) {
d.style.left = e.clientX;
d.style.top = e.clientX * Math.tan(angle * Math.PI / 180);
}
}
}
</script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With