• 请不要在回答技术问题时复制粘贴 AI 生成的内容
alwayshere
V2EX  ›  程序员

图片瀑布流用 masonry.js 需要等图片加载完了才自动排列,有没有其他 js 实现的?

  •  
  •   alwayshere · Dec 13, 2018 · 1808 views
    This topic created in 2712 days ago, the information mentioned may be changed or developed.

    本来想用 css column 的,但是兼容性太差,感觉还是用 js 生成瀑布流好点,但是 masonry.js 要等所有图片加载完了才能得出每张图片的宽高再自动排列,有没有兼容性比较好的 js,我通过提前输出每张图片的预设宽高,迅速生成响应式的瀑布流,就像花瓣网那样

    3 replies    2018-12-14 01:20:22 +08:00
    rabbbit
        1
    rabbbit  
       Dec 13, 2018
    试试用 width 和 height attribute 代替 CSS

    <img width="100" height="100">
    这样做图片未加载时也是固定宽高
    caliburn1994
        2
    caliburn1994  
       Dec 14, 2018 via Android
    caliburn1994
        3
    caliburn1994  
       Dec 14, 2018 via Android
    nanogallery2 挺好用的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2924 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 06:47 · PVG 14:47 · LAX 23:47 · JFK 02:47
    ♥ Do have faith in what you're doing.