Greasy Fork is available in English.

Element Draggable

A lightweight draggable library.

Αυτός ο κώδικας δεν πρέπει να εγκατασταθεί άμεσα. Είναι μια βιβλιοθήκη για άλλους κώδικες που περιλαμβάνεται μέσω της οδηγίας meta // @require https://update.greasyfork.org/scripts/587662/1879553/Element%20Draggable.js

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

Δημιουργός
ryxel
Έκδοση
1.0
Δημιουργήθηκε την
19/07/2026
Ενημερώθηκε την
19/07/2026
Μέγεθος
6 KB
Άδεια
MIT

Draggable

A JavaScript library for dragging elements, usable in Tampermonkey scripts or regular web pages.

Usage

const element = document.querySelector('#element');
const handle = document.querySelector('#handle');

const options = {
    handle: handle,
    savePosition: true,
    id: 'example'
};

const drag = new Draggable(element, options);

Parameters

  • element (HTMLElement): The target DOM element to be dragged.
  • options (Object, optional): Configuration object.

Options Configuration

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.

Notes

  • A unique id must be provided when position saving is enabled.
  • When using in a Tampermonkey script, if position saving is enabled, it is recommended to declare the following permissions in the script header:
// @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.

Destroy Instance

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();