本文介绍了在同位素onLayout中定义/调用函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用并且它说:

与回调类似,onLayout是每次Isotope实例运行时都会触发的函数布局逻辑。

"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' });

我没有$ elems,但据我所知,这意味着当onLayout 已经完成我可以运行我想要的东西,我想运行它:

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

但()中的$ elems是怎么回事?

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

谢谢

推荐答案

您可以将自定义事件绑定到以下元素:

You can bind custom events on to elements like so:

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

然后用 .trigger():

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

使用它,我认为你应该可以很容易地设置你想要的东西。

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

更新:

而不是调用此代码:

$('#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').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");
    }
});

这篇关于在同位素onLayout中定义/调用函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 04:20