Drag, drop and snap
How do I make an drag, drop and snap?
Drag and drop in a list and snaps in order. What is a drag, drop and snap? How do you make a drag, drop and snap? This script and codes were developed by Darby Rathbone on 03 October 2022, Monday.
Drag, drop and snap - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>drag, drop and snap</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> <ul> <li class='drag'><span>this is 1</span> </li> <li class='drag'><span>this is 2</span> </li> <li class='drag'><span>this is 3</span> </li> <li class='drag'><span>this is 4</span> </li>
</ul><ul> <li class='drag'><span>this is 1</span> </li> <li class='drag'><span>this is 2</span> </li> <li class='drag'><span>this is 3</span> </li> <li class='drag'><span>this is 4</span> </li>
</ul> <script src="js/index.js"></script>
</body>
</html>
Drag, drop and snap - Script Codes CSS Codes
.drag { cursor:move; text-align: center; width:auto; height:auto; border:ridge 3px #cccccc; overflow: hidden; display:flex; padding:10px; margin:5px;
}
ul { outline:inset 3px; overflow:hidden; width:auto;
}
Drag, drop and snap - Script Codes JS Codes
var when = function (event, conditioncallback, truecallback, checkparents, falsecallback) { this.addEventListener(event, function (e) { var p = []; p.push(e.target); if (checkparents) { while (p[p.length - 1].parentElement) { p.push(p[p.length - 1].parentElement) } } if ((!(p.some(function (f) { if (conditioncallback.call(f)) { truecallback.bind(f, e).call(); return true } else { return false } }))) && falsecallback) { falsecallback() } })
};
var dragging, offset;
var dragables = document.getElementsByClassName('drag');
[].slice.call(dragables).reverse().forEach(function (e) { var b = getComputedStyle(e); console.log(b); e.style.top = b.top; e.style.left = b.left
});
var pm = [0, 0];
when('mousedown',
function () { event.preventDefault(); return this.classList.contains('drag')
},
function (e) { var order = [].slice.call(dragables).sort(function (a, b) { return parseInt(getComputedStyle(b)['z-index']) - parseInt(getComputedStyle(a)['z-index']) }); order.unshift(this); order = order.reverse(); order.forEach(function (a, i) { if (!a.style) a.style; a.style['z-index'] = i }); this.style.position = 'relative'; dragging = this; var b = getComputedStyle(this); pm = [e.pageX, e.pageY]; offset = [e.pageX - (parseInt(b.left) || 0), e.pageY - (parseInt(b.top) || 0)]; e.preventDefault()
}, true);
when('mousemove',
function () { return dragging
},
function (e) { var dy = e.pageY - pm[1]; var before = dragging.getBoundingClientRect(); var ev = [e.pageX, e.pageY]; if (dy > 0) { ev[1] = (before.bottom) } if (dy < -0) { ev[1] = (before.top - 1) } var ex = document.elementFromPoint(ev[0], ev[1]); if (ex && dragging !== ex) { if (dragging.parentElement === ex.parentElement) { ex.parentElement.insertBefore(dragging, ex); if (dy > 0) { ex.parentElement.insertBefore(ex, dragging) } var after = dragging.getBoundingClientRect(); offset[1] += after.top - before.top } } if (dy) { pm = [e.pageX, e.pageY]; dragging.style.top = e.pageY - offset[1] + 'px'; dragging.style.left = e.pageX - offset[0] + 'px' } e.preventDefault()
});
when('mouseup',
function () { return dragging
},
function (e) { dragging.style.top = 0 + 'px'; dragging.style.left = 0 + 'px'; e.preventDefault(); dragging.style.position = ''; dragging = false; offset = []
});
Developer | Darby Rathbone |
Username | blackkbot |
Uploaded | October 03, 2022 |
Rating | 3 |
Size | 2,542 Kb |
Views | 30,360 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Canvas buffer | 2,791 Kb |
Graphing equations | 3,529 Kb |
3d hand | 18,673 Kb |
3d css transformations | 2,652 Kb |
3d pure javascript 2d canvas | 2,600 Kb |
Sphere detail | 2,558 Kb |
3d pure javascript 2d canvas | 2,667 Kb |
Perlin noise on worker | 2,989 Kb |
Ball physics | 3,874 Kb |
A linearly interpolated spline | 2,328 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Dragonball Dragon Radar | DouglasGlover | 2,157 Kb |
3D Text in Sass | Bookcasey | 2,766 Kb |
Degree Picker | Idered | 4,307 Kb |
Confirm Close Of Foundation Reveal Modal | Winghouchan | 1,818 Kb |
Progressively reveal dots on a Bezier curve | GreenSock | 2,489 Kb |
Flat UI Button | Honchoman | 2,289 Kb |
Tree growth tests | Orchard | 3,818 Kb |
Smoke Shader - Frame Buffer | Omarshe7ta | 2,672 Kb |
Login-ng-modal | Heedoo | 3,566 Kb |
A Pen by aleen42 | Aleen42 | 11,473 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!