最近用到瀑布流使用的插件masonry.js 時(shí),當(dāng)item寬度的不同尺寸超過三個(gè)的時(shí)候,發(fā)現(xiàn)靠近邊緣的一個(gè) 老是掉下來。甚是麻煩...
后來翻了一下官網(wǎng),才最終解決了bug

解決辦法.jpg
原因是:
當(dāng)我們配置項(xiàng)沒有寫上 columnWidth 的時(shí)候,插件會將第一個(gè)item作為卡片的通用尺寸。官網(wǎng)也有做如下警告提示:
We recommend setting columnWidth. If columnWidth is not set, Masonry will use the outer width of the first item.
所以在加入一個(gè)空的item,然后配置項(xiàng)加上columnWidth,
插件就會正確識別不同width啦~~