Coder Social home page Coder Social logo

react-lazy-media's Introduction

react-lazy-media

npm Build Status GitHub license

Lazy load image, picture, video, and iframe media React components. react-lazy-media uses yall-js under the hood to handle lazy loading.

Polyfilled with the Intersection Observer Polyfill

Chrome
Firefox
Safari
6+
Edge
Internet Explorer
10+
Opera
Android
4.4+

Installation and Usage:

npm i -S react-lazy-media

Include the Component:

import React from 'react'
import { LazyImage } from 'react-lazy-media'

class Component extends React.Component {

  render() {
    return (
      <LazyImage
        classes={['myLazyImage']}
        src={'./hero.png'}
      />
    );
  }
}

You can import LazyImage LazyVideo LazyIframe LazyBackground LazyWebpPicture respectively.

Component Examples

Common

The following APIs are shared by every component.

Name Type Default Description
classes Array [] Additional CSS classes (in addition to 'lazy' for the media element (img, video, iframe)
id string '' id for the media element (img, video, iframe)

LazyImage

Lazy loads an image element. Supports loading a low-quality image placeholder.

Name Type Default Description
alt string [] Alt text for the img
src string (Required) N/A - Required src for the img
width string '' width for the img
height string '' height for the img
lqip string '' src for a loq quality image placeholder. will always be loaded and then replaced with actual src img

LazyBackground

Lazy loads a background image for a div.

Name Type Default Description
src string (Required) N/A - Required src for the background image

LazyVideo

Lazy loads an HTML5 video.

Name Type Default Description
src string (Required) N/A - Required src for the video
width string '' width for the video
height string '' height for the video
poster string '' poster image for the video (before it loads/plays)
controls bool true whether or not the video should display controls
preload bool false whether or not the video should be preloaded
autoplay bool false whether or not the video should autoplay
loop bool false whether or not the video should loop
muted bool false whether or not the video should be muted

LazyIframe

Lazy loads an iframe.

Name Type Default Description
src string (Required) N/A - Required src for the iframe

LazyWebpPicture

Lazy loads an HTML5 picture. Attempts to load a Webp version of the asset first, and falls back to original src. Most of the props are passed down to the LazyImage child of this component.

Name Type Default Description
alt string [] Alt text for the img
src string (Required) N/A - Required src for the img
width string '' width for the img
height string '' height for the img
lqip string '' src for a loq quality image placeholder. will always be loaded and then replaced with actual src img
webp string '' The webp src for the img. Will suffix the src prop of not provided (e.g. hero.png => hero.png.webp)

Todo

[] Add more configurable component: LazyPicture [] Add code example for each component in readme

react-lazy-media's People

Contributors

dependabot[bot] avatar richiemcilroy avatar smrubin avatar vikramp93 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

richiemcilroy

react-lazy-media's Issues

can't remove controls in LazyVideo

Hello.

This is my code.

<LazyVideo
    src={content.mobileVideo}
    width="100"
    height="100"
    poster={content.mobileImage}
    control={false}
    autoplay={true}
    loop={true}
    muted={true}
  />

As you can see I have set control false. But controls still exists.
Let me know how to hide control bar in LazyVideo.

Thanks.

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.