A React component for responsive images in desktop and mobile browsers. Featuring Imager.js!
React is used for the initial component rendering. Its batched state update mechanism is then used to handle multiple image size at once, to avoid layout thrashing.
Imager.jsx is a browserifiable Node module.
npm i --save imager.jsx
If you want to generate a static artifact, clone the repository and run the following commands:
git clone https://github.com/oncletom/Imager.jsx.git imager.jsx && cd imager.jsxnpm installnpm run buildopen demo/index.html
Imager.jsx is a two-steps use.
The React Factory
The factory associates an Imager.js behaviour with a React component.
var Imager = ;var ResponsiveImage =;
The React Component
The React component is used to render a responsive image (an
<img /> HTML element).
The only mandatory attribute is
src, the equivalent of Imager.js
alt are respectively rendered as
alt HTML attributes.
Clone the project and open the demo.html page for live examples.
<img /> element
This is rendered as:
<div style="background-image: ..." /> element
This is rendered as:
The MIT License (MIT) Copyright (c) 2014 Thomas Parisot Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.