MyDropdown

原生js实现简洁的下拉菜单

Dieses Skript sollte nicht direkt installiert werden. Es handelt sich hier um eine Bibliothek für andere Skripte, welche über folgenden Befehl in den Metadaten eines Skriptes eingebunden wird // @require https://update.greasyfork.org/scripts/463933/1177909/MyDropdown.js

Du musst eine Erweiterung wie Tampermonkey, Greasemonkey oder Violentmonkey installieren, um dieses Skript zu installieren.

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

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

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

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

Sie müssten eine Skript Manager Erweiterung installieren damit sie dieses Skript installieren können

(Ich habe schon ein Skript Manager, Lass mich es installieren!)

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.

(I already have a user style manager, let me install it!)

Autor
wish king
Version
0.0.1.20230419042947
Erstellt am
13.04.2023
Letzte Aktualisierung
19.04.2023
Größe
16,4 KB
Lizenz
n/a

原生js实现简洁的下拉菜单

截图:



在线预览:
https://jsrun.net/3cdKp/embedded/all/light


使用示例:

var clicked = function(e) {
    console.log("clicked", e.target.dataset.value)
}
new MyDropdown({
    el: ".my-dropdown-btn",
    maxWidth: '200px',
    maxHeight: '400px',
    //支持click mouseenter dblclick等,默认click
    toggleEvent: 'mouseenter',
    items: [
        {
            name: 'Home',
            value: 'home',
            icon: '',
            fn: clicked
        },
        {
            name: 'About',
            value: 'about',
            icon: '',
            selected: false,
            fn: clicked
        },
        {
            name: 'Contact',
            value: 'contact',
            icon: '',
            fn: clicked,
            //icon也支持对象传值,同样具有html和fn属性
            op: {
                html: `×`,
                fn: function(e) {
                    console.log('op clicked');
                }
            }
        }
    ],
    created: function(menu) {
        console.log('After created callback1');
    },
    shown: function(menu) {
        console.log('After shown callback1');
    },
    hidden: function(menu) {
        console.log('After hidden callback1');
    }
});