GithubHelp home page GithubHelp logo

littleboy1988 / react-image-responsive Goto Github PK

View Code? Open in Web Editor NEW

This project forked from youpinadi/react-image-responsive

0.0 1.0 0.0 256 KB

An image that is responsive to its width on the screen (can be also a background image) Works with retina displays.

JavaScript 100.00%

react-image-responsive's Introduction

react-image-responsive

An image that is responsive to its width on the screen (can be also a background image) Works with retina displays.

Why?

Media queries only take care of the screen size and resolution, not about the actual image size. What if your image is 300px on an iPhone and only 100px on a larger screen?

Installation

npm install react-image-responsive

Usage (ES6 + JSX):

import React from 'react';
import ImageResponsive, {Source} from 'react-image-responsive';

React.render(
  <div>
    <ImageResponsive type="image" src="http://placehold.it/50x50" width="50%" height="200px">
        <Source src="http://placehold.it/1600x300" maxWidth={1600}/>
        <Source src="http://placehold.it/300x300"  maxWidth={300}/>
        <Source src="http://placehold.it/500x300"  maxWidth={500}/>
        <Source src="http://placehold.it/800x300"  maxWidth={800}/>
        <Source src="http://placehold.it/1000x300" maxWidth={1000}/>
    </ImageResponsive>
    <br/>
    <br/>
    <ImageResponsive type="background-image" src="http://placehold.it/50x50" width="50%" height="200px" style={{transition: 'background-image .3s linear'}}>
        <Source src="http://placehold.it/300x300"  maxWidth={300}/>
        <Source src="http://placehold.it/500x300"  maxWidth={500}/>
        <Source src="http://placehold.it/800x300"  maxWidth={800}/>
        <Source src="http://placehold.it/1600x300" maxWidth={1600}/>
        <Source src="http://placehold.it/1000x300" maxWidth={1000}/>
        This one is just a background image
        <br/>
        It looks perfect
    </ImageResponsive>
  </div>,
  document.getElementById('root')
);

react-image-responsive's People

Contributors

romainberger avatar youpinadi avatar

Watchers

 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.