Define/call a function in isotope onLayout

[亡魂溺海] 提交于 2019-12-08 07:48:37

问题


I'm using http://isotope.metafizzy.co/docs/options.html#onlayout and it says this:

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

$('#container').isotope({
   onLayout: function( $elems ) {
    // `this` refers to jQuery object of the container element
    console.log( this.height() );
    // callback provides jQuery object of laid-out item elements
    $elems.css({ background: 'blue' });
    }
});

That means that when "Layout" has finished i can run this:

 $elems.css({ background: 'blue' });

I don't have "$elems" but from what i can understand that means that when "onLayout" has finished i can run what i want and I would like to run this:

$("#container").width(); 
$("#head").animate({ width: newWidth}, "fast");

But how and what is "$elems" inside the "( )" ?

Thanks


回答1:


You can bind custom events on to elements like so:

$('#container').bind('my_event', function ()
{
    alert('my_event has just fired!');
});

And then call it with .trigger():

$('#container').trigger('my_event');

Using this, you should be able to set up what you want pretty easily, I think.


Update:

Instead of calling this code:

$('#container').isotope({
   onLayout: function( $elems ) {
    // `this` refers to jQuery object of the container element
    console.log( this.height() );
    // callback provides jQuery object of laid-out item elements
    $elems.css({ background: 'blue' });
    }
});

Call this:

$('#container').isotope({
   onLayout: function( $elems ) {
        // `this` refers to jQuery object of the container element
        console.log( this.height() );
        // callback provides jQuery object of laid-out item elements
        $elems.css({ background: 'blue' });
        $("#container").width(); 
        $("#head").animate({ width: newWidth}, "fast");
    }
});


来源:https://stackoverflow.com/questions/9236945/define-call-a-function-in-isotope-onlayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!