知方号

知方号

Responsive images for every screen size and device with React

Before you get started

This library requires that you are using some image server that allows for image resizing and retaining image aspect ratio. Many use this out of the box and if you’d like to quickly get one up and running as you follow along, I recommend node-image-steam. It has a driver for file system access for local testing and can also access images in Amazon S3, and others.

Setup

To configure this component to work with your existing app, you’ll need to import and call initImages, passing an object for configuration. imageResolver is where you will take the processed image object with calculated dimensions and generate a URL that conforms to how your CMS resizes images.

The example below connects to a local instance of image-steam and will resize image based on the users viewport and pixel density.

This example shows the most basic way to integrate, for all available props and settings please view the readme

To render an image:

When this image is rendered (above the fold or almost visible), the imageResolver function will run and that will become the source of the image. Rendering an image that is perfectly scaled for its container.

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至lizi9903@foxmail.com举报,一经查实,本站将立刻删除。