Coder Social home page Coder Social logo

waterfall's Introduction

jswaterfall

效果展示

该插件在 React 项目中的运用

feature

  • 支持同步/异步获取图片数据(基于发布/订阅模式)

  • 按需加载(每次渲染指定的条数)

  • 兼容各尺寸的屏幕

  • 无依赖(打包 JS 文件 4 kb)

  • 较好的扩展性

  • 图片懒加载

  • 兼容性扩展

  • UI 优化

usage

npm install jswaterfall --save
window.onload = function() {
  const waterfall = new Waterfall({
    number: 20,                 // 一次性加载的图片个数;必填
    // fixWidth: 1250,          // 容器 width: 选填:填上后会使 window.resize 失效,fixWidth 属性优先级大于 width 属性
    // width: 1250,             // 容器 width;选填: 默认为浏览器的宽度,(后期考虑可以设置为某个节点的宽度)
    // container: 'waterfall',  // 容器 id;选填:默认为 'waterfall'
    // scrollElem: 'content',   // 绑定 scroll 的节点 id,默认为 window
  })

  waterfall.on("load", function () {
    // 模拟 ajax 异步添加图片
    setTimeout(function () {
      const $waterfall = document.getElementById('waterfall')
      for (let i = 0; i < 20; i++) {
        const img = document.createElement('img')
        img.setAttribute('src', `images/${i + 1}.png`)
        img.setAttribute('class', 'waterfall-box')
        $waterfall.appendChild(img)
      }
      waterfall.done() // 同步/异步写法都要加上这句,通知加载完成
    }, 1000)
  })
}

waterfall's People

Contributors

muyunyun avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.