Dragster
Better HTML5 drag events
Install / Use
/learn @avocode/DragsterREADME
Dragster-avocode-fork
This is a fork of original dragster package from Ben Smithett.
HTML5 dragenter and dragleave events are crap. Dragster gives you sane new dragster:enter and dragster:leave events that behave just like mouseenter and mouseleave.
Detecting when the user has dragged over a dropzone with child elements sucks. It usually involves transparent overlay elements, listening to the constantly-firing dragover event or nuking every other event with pointer-events: none.
Dragster is tiny (417 bytes minified & gzipped), unobtrusive & doesn't do much - it just add a couple of event listeners for dragenter and dragleave on the elements that you specify. It never does anything automagically, and doesn't cancel the original events.
Dragster works in latest stable Chrome, Firefox, Safari & Opera. It does nothing at all in IE 7-10 (IE doesn't support DOM event constructors).
@catmanjan maintains a jQuery plugin version of Dragster if you'd like better cross browser support.
Installation
npm install dragster-avocode-fork
Setup
Just include Dragster in your app, then bootstrap your dropzone elements with Dragster so they can start emitting dragster: events.
var dropzone = document.getElementById( "my-dropzone" );
new Dragster( dropzone );
Then you can add some plain old event listeners without pulling your hair out.
document.addEventListener( "dragster:enter", function (e) {
e.target.classList.add( "dragged-over" );
}, false );
document.addEventListener( "dragster:leave", function (e) {
e.target.classList.remove( "dragged-over" );
}, false );
You can teardown a Dragster instance by calling removeListeners
dragster = new Dragster( dropzone );
// Dragging over dropzone emits dragster: events
dragster.removeListeners();
// Dragster events no longer emitted from dropzone
Contributing
Dragster is written in CoffeeScript.
npm install
npm run build
License
Dragster is released under the MIT License
Related Skills
node-connect
349.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.7kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
349.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
349.7kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
