我正在将 David Desandros Isotope用于新站点,但现在看来我无法使用 jquery 找到每个元素的位置。具体来说,我试图在悬停时附加一个工具提示,但通常我想知道在 Isotope 格式化它们之后如何获取每个锚点的 position() 。
到目前为止,每个元素都为 left、margin-left、position().left 和我能想到的所有其他定位属性显示一个“0”。
我正在将 David Desandros Isotope用于新站点,但现在看来我无法使用 jquery 找到每个元素的位置。具体来说,我试图在悬停时附加一个工具提示,但通常我想知道在 Isotope 格式化它们之后如何获取每个锚点的 position() 。
到目前为止,每个元素都为 left、margin-left、position().left 和我能想到的所有其他定位属性显示一个“0”。
有关itemPositionDataEnabled,请参阅同位素文档
$('#container').isotope({
itemSelector: '.element',
itemPositionDataEnabled: true
})
// log position of each item
.find('.element').each(function(){
var position = $(this).data('isotope-item-position');
console.log('item position is x: ' + position.x + ', y: ' + position.y );
});
嘿,在查看Isotope在 Firebug 中的一个演示中的源代码后,我发现位置是通过以下方式计算的:
-moz-transform: translate(#px, #px)
和
-webkit-transform: translate(#px, #px)
我不确定其他浏览器(例如 IE)使用的是什么,但您应该可以通过这种方式访问它们的位置。