ImageBlock
ImageBlock is a dead-simple way to use an <img>
element like you would background-size: cover;
.
Why Use ImageBlock?
There are numerous reasons to use ImageBlock:
- You want responsive background images
- You want to use an
alt
attribute with a background image - You want to use the
transform
property with a background image
Dependencies
- jQuery
Quick Start
Getting started is ridiculously easy:
- Make sure you have jQuery.
- Include the
dist
files,image-block.js
andimage-blocks.css
. - Put an
img.image-block-bg
inside adiv.image-block
. - Put a
.image-block-content
after theimg.image-block-bg
(optional).
Note: to render properly, .image-block
must either:
- Have a defined width or height
- Contain an
.image-block-content
with inner content.
For example:
ImageBlock Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Advanced Configuration
If you'd like to go a bit further, follow these steps to reduce the total number of HTTP requests and improve your workflow.
First, install ImageBlock via NPM:
npm install image-block --save
From there, you can import the src
files in JavaScript and Sass:
windowjQuery =
And that's it!