javascript - 当 child 被触发时,同位素 columnshift 不起作用

标签 javascript jquery jquery-masonry jquery-isotope

我正在尝试使用此布局:masonry column shift

当我点击主要项目时,这对我有用:

$container.find('.wrapper').click(function(){
        $(this).css({ height: "+=100" });
        // note that element is passed in, not jQuery object
        $container.isotope( 'shiftColumnOfItem', this );
});

这就是我想要的(点击 child 时触发尺寸变化):

$container.find('.wrapper li').click(function(){
        var closestwrapper = $(this).closest('.wrapper');
        closestwrapper.css({ height: "+=100" });
        // note that element is passed in, not jQuery object
        $container.isotope( 'shiftColumnOfItem', this );
});

大小改变但不会移动列。我还尝试使用 closestwrapper 而不是 this

在演示页面上有一条我看不懂的评论:

// note that element is passed in, not jQuery object

最佳答案

"On the demo page there is a comment that I don't understand:"

// note that element is passed in, not jQuery object

DOM 元素是表示页面上元素的对象。 jQuery 对象是由 jQuery 库构造的对象,通常包含一个或多个 DOM 元素。

在您的第一个 isotope() 调用中,您将传递 this,在这种情况下它是一个 DOM 元素。

但在第二个版本中,如果您尝试传递 closestwrapper,您传递的是一个包含 DOM 元素的 jQuery 对象。因此,您需要从 jQuery 对象中提取 DOM 元素。

jQuery 将 DOM 元素存储在从零开始的数字索引处,因此您可以使用典型的对象成员运算符来获取 DOM 元素。

// -----------------------------------------------------v
$container.isotope( 'shiftColumnOfItem', closestwrapper[0] );

关于javascript - 当 child 被触发时,同位素 columnshift 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16379395/

相关文章:

javascript - 如何获得带有选择/取消选择所有功能和不确定值的 angular.js 复选框?

javascript - 从文本区域清除换行符

javascript - Materialise - 使用 Carousel 功能

javascript - addClass 活跃到 Bootstrap 导航

jquery - 具有实时验证功能的 HTML 5 表单插件?

javascript - 更改页面后关闭选项卡窗口浏览器

javascript - 使用 jquery 获取类

javascript - 如果屏幕尺寸小于,则停止脚本工作

html - 砌体额外的排水沟

javascript - Masonry:使用 2 列布局,如何让 1 列比另一列宽?