
allonsh.js is a lightweight JavaScript library that enables you to implement drag and drop functionality using native elementFromPoint detection.
This native browser method provides accurate element detection during drag operations without the overhead of complex collision detection algorithms or DOM traversal logic that other libraries often require.
Features:
- Zero Dependencies: Completely standalone with no external library requirements.
- Modern Browser Support: Works reliably in browsers that support Pointer Events.
- Automatic Viewport Scrolling: Handles edge scrolling when dragging near viewport boundaries.
- Custom Event System: Provides
allonsh-dragstart,allonsh-dragover, andallonsh-dropevents for interaction handling. - Snap-to-Center Option: Built-in functionality to automatically center elements within drop zones.
How to use it:
1. Define the elements you want to drag and the areas where you can drop them.
<div class="draggable">Drag me</div> <div class="dropzone" id="dropzone">Drop here</div>
2. Import the library and initialize it by passing a CSS selector for your draggable elements.
import Allonsh from './src/allonsh.js';
const dragManager = new Allonsh('.draggable');3. The library works by dispatching custom events. You listen for these events on your dropzone elements to control the behavior.
const dropzone = document.getElementById('dropzone');
dragManager.enableSnapping(true);
dragManager.setSnapMode('bottom-right');
dragManager.registerDropzone('#dropzone', (draggedEl, dropzone) => {
console.log('Dropped:', draggedEl.textContent);
});
4. More API methods.
registerDropzone(selector, onDrop): Registers a dropzone with optional drop handler callback.enableSnapping(boolen): Enables or disables snapping behavior.setSnapMode(mode): Set snapping mode: “center”, “top-left”, “top-right”, “bottom-left”, “bottom-right”, “edge”
5. Event handlers.
allonsh-dragstart: Fired on the dragged element when the drag operation begins.allonsh-dragover: Fired on the element currently underneath the cursor during a drag.allonsh-drop: Fired on the element where the dragged element is dropped. The eventdetailobject contains thedraggedEl.
FAQs
Q: Does allonsh.js work on mobile devices?
A: The library currently uses mouse events, so it doesn’t work on touch devices. You’d need to implement touch event handlers separately or use a different library for mobile drag and drop functionality.
Q: Can I drag elements between different containers or iframes?
A: Elements can be dragged between any containers within the same document. Cross-iframe dragging isn’t supported since elementFromPoint doesn’t work across frame boundaries.
Q: How do I prevent certain elements from being drop targets?
A: Since drop detection uses elementFromPoint, you can prevent drops by not adding event listeners to those elements or by checking the element type in your event handlers before processing the drop.
Q: What happens if I have overlapping drop zones?
A: The library will detect whichever element is topmost in the DOM stacking order at the cursor position. You can control this behavior using CSS z-index values on your drop zones.
Q: How does allonsh.js compare to the native HTML5 Drag and Drop API?
A: It offers a simpler, more predictable developer experience. You work with standard custom events and have full control over the element’s appearance during the drag. The native API can be quirky and less intuitive.
Changelog:
v0.1.0 (08/24/2025)
- Update







