admin管理员组

文章数量:1416325

Isotope provides two places where you can supply callback functions:

container.isotope({
    itemSelector: itemSelector,
    layoutMode: 'fitRows',
    onLayout: function() {alert('onLayout callback')}

}, function() {alert('anon callback')});

I don't know what the difference between these two are - they both seem to be called exactly once, after the layout has pleted. I've looked through the docs, but all I can find is

Similiar to a callback, onLayout is a function that will be triggered after every time an Isotope instance runs through its layout logic.

Isotope provides two places where you can supply callback functions:

container.isotope({
    itemSelector: itemSelector,
    layoutMode: 'fitRows',
    onLayout: function() {alert('onLayout callback')}

}, function() {alert('anon callback')});

I don't know what the difference between these two are - they both seem to be called exactly once, after the layout has pleted. I've looked through the docs, but all I can find is

Similiar to a callback, onLayout is a function that will be triggered after every time an Isotope instance runs through its layout logic.

Share Improve this question asked Feb 21, 2012 at 15:09 DónalDónal 188k177 gold badges586 silver badges844 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

According to the source code, there is no difference. Three callback functions may be called when layout pletes: the one passed in the final argument to isotope(), the one passed in the onLayout option and the one passed in the plete member of the animationOptions option.

The relevant parts of the source are:

// [...]    
} else if ( callback || onLayout || animOpts.plete ) {
    // has callback
    var isCallbackTriggered = false,
        // array of possible callbacks to trigger
        callbacks = [ callback, onLayout, animOpts.plete ],
        instance = this;
    triggerCallbackNow = true;
    // trigger callback only once
    callbackFn = function() {
        if ( isCallbackTriggered ) {
            return;
        }
        var hollaback;
        for (var i=0, len = callbacks.length; i < len; i++) {
            hollaback = callbacks[i];
            if ( typeof hollaback === 'function' ) {
                hollaback.call( instance.element, $elems );
            }
        }
        isCallbackTriggered = true;
    };
    // [...]
}  

As you can see, an array is built with the three potential callbacks, and callbackFn() calls each one in sequence if it's a function.

本文标签: javascriptisotope callback functionsStack Overflow