2024 年 11 月
 123
45678910
11121314151617
18192021222324
252627282930  

近期发布

近期评论

    2024 年 11 月 17 日

    Neusofts

    科技改变生活,创新引领未来

    Bean.js

    Bean is a small, fast, cross-platform, framework-agnostic event manager designed for desktop, mobile, and touch-based browsers. In its simplest form – it works like this:

    bean.on(element, 'click', function (e) {
    console.log('hello');
    });
    


    Bean is included in Ender’s starter pack, “The Jeesh”. More details on the Ender interface below.

    API

    Bean has five main methods, each packing quite a punch.

    bean.on()
    bean.one()
    bean.off()
    bean.clone()
    bean.fire()
    
    on(element, eventType[, selector], handler[, args ])
    
    bean.on() 

    lets you attach event listeners to both elements and objects.

    Arguments

    element / object (DOM Element or Object) – an HTML DOM element or any JavaScript Object
    event type(s) (String) – an event (or multiple events, space separated) to listen to
    selector (optional String) – a CSS DOM Element selector string to bind the listener to child elements matching the selector
    handler (Function) – the callback function
    args (optional) – additional arguments to pas to the callback function when triggered
    Optionally, event types and handlers can be passed in an object of the form { ‘eventType’: handler } as the second argument.

    Examples

    // simple
    bean.on(element, 'click', handler);
    
    // optional arguments passed to handler
    bean.on(element, 'click', function(e, o1, o2) {
    console.log(o1, o2);
    }, 'fat', 'ded');
    
    // multiple events
    bean.on(element, 'keydown keyup', handler);
    
    // multiple handlers
    bean.on(element, {
    click: function (e) {},
    mouseover: function (e) {},
    'focus blur': function (e) {}
    });