npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-lazyload-pic

v1.0.4

Published

a lazyload-pic component for React

Downloads

13

Readme

English | 中文

react-lazyload-pic

图片以及图片列表懒加载的react组件

Installation

$ npm install react-lazyload-pic --save
or
$ yarn add react-lazyload-pic

Usage

方法1 仅针对当前所要展示的大图做完全加载后展示,未完全加载时图片用占位图替代

lazyloadlist.gif

import { PicLazyLoad } from "react-lazyload-pic";
import Sevn from '@/assets/sevn.jpg'

class App extends React.Component {
  state = {
    loaded : false
  }

  render() {
    const that = this;
    const { loaded } = that.state;
    const onLoad = () => {
      that.setState({
        loaded:true
      })
    }
   
    return <div className="container"> 
              <PicLazyLoad
                img={Sevn}             // 图片
                skeleton="newSkeleton" // 占位图css样式(className)
                imgClassName="sevn"    // 图片的样式(className)
                alt="sevn"
                loaded={loaded}
                onLoad={onLoad}
              /> 
            </div>
  }
}

export default App;


//css 
{
  .container {
    display: flex;
    width: 100%;
    height: 100vh;
    font-size: 30px;
  }

  .newSkeleton,
  .sevn {
    width: 200px;
    height: 100px;
  }
}

方法2 懒加载图片列表,当图片加载才会被显示在列表内 lazyloadlist.gif

import { LazyLoadPic } from "react-lazyload-pic";

class App extends React.Component {
  constructor() {
    super();
    this.state = {
      imgArr: []
    };
  }

  componentDidMount() {
    const that = this;
    let arr = [];

    for (let i = 1; i < 17; i++) {
      arr.push({ url: require(`./images/${i}.png`) });
    }

    that.setState({
      imgArr: _.concat(arr)
    });
  }

  render() {
    const that = this;
    const { imgArr } = that.state;

    return (
      <div className="container">
        <LazyLoadPic
          boxClassName="boxContainer"
          imgBoxClassName="imgBoxContainer"
          imgClassName="imgContainer"
          imgArr={imgArr}
        />
      </div>
    );
  }
}

export default App;

Properties

  //方法1
  static propTypes = {
    onLoaded: PropTypes.func.isRequired,
    loaded: PropTypes.bool.isRequired,
    img: PropTypes.string.isRequired,
    alt: PropTypes.string.isRequired,
    imgClassName: PropTypes.string,
    skeleton: PropTypes.string
  };

  static defaultProps = {
    alt: "",
  };

  //方法2
   static propTypes = {
    imgClassName: PropTypes.string,
    imgBoxClassName: PropTypes.string,
    alt: PropTypes.string
  };

  static defaultProps = {
    alt: ""
  };

License

MIT