Add Inline Background Images Using Data Attribute - jQuery EasyImg

File Size: 117 KB
Views Total: 1321
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Add Inline Background Images Using Data Attribute - jQuery EasyImg

EasyImg is a dead simple and cross-browser jQuery plugin which adds inline background images to container elements using HTML data attributes.

Use this plugin to quickly add background images without the need of using background-image style.

How to use it:

1. Put all your background images in the images folder.


2. Add background images to the container elements using the data-img attribute as follows:

<div data-img="1.jpg">
  Background 1

<div data-img="2.jpg">
  Background 2

<div data-img="3.jpg">
  Background 3


3. Include jQuery library and the jQuery EasyImg plugin's files at the bottom of the webpage.

<script src="" 
<script src="easyImg.min.js"></script>

4. Initialize the plugin and done.


5. Change the default folder name/path that holds your background images.

  baseFolder: './images/'

6. Change the default data attribute.

  selector: 'data-img'

7. Default CSS styles of background images.

selector {
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;

This awesome jQuery plugin is developed by HimasRafeek. For more Advanced Usages, please check the demo page or visit the official website.