A lightweight draggable library.
이 스크립트는 직접 설치하는 용도가 아닙니다. 다른 스크립트에서 메타 지시문 // @require https://update.greasyfork.org/scripts/587662/1879553/Element%20Draggable.js을(를) 사용하여 포함하는 라이브러리입니다.
A JavaScript library for dragging elements, usable in Tampermonkey scripts or regular web pages.
const element = document.querySelector('#element');
const handle = document.querySelector('#handle');
const options = {
handle: handle,
savePosition: true,
id: 'example'
};
const drag = new Draggable(element, options);
| Parameter | Type | Default | Description |
|---|---|---|---|
| handle | HTMLElement | element | Specifies the drag handle. |
| savePosition | boolean | false | Whether to save the element position. |
| id | string | null | Unique identifier used for saving the position. Only works when savePosition is true. |
id must be provided when position saving is enabled.// @grant GM_getValue
// @grant GM_setValue
With these permissions, position data will be stored through the userscript manager and can persist across pages.
If the permissions are not declared, position data will be stored in the current page's localStorage.
When the dragging functionality is no longer needed or the element is removed, the instance should be manually destroyed to release resources and remove event listeners.
drag.destroy();