Convert Image Into Background Image - convertToBackground.js

File Size: 4.95 KB
Views Total: 1962
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
Convert Image Into Background Image - convertToBackground.js

Yet another jQuery Image To Background plugin which converts the original images into CSS background images in their parent containers, while maintaining the original aspect ratios.

Can be used as an alternative to the responsive image solution for your cross-platform project.

See also:

How to use it:

1. Wrap your image into a container element.

<div class="example">
  <img src="">

2. Include jQuery JavaScript library and the minified version of the jQuery convertToBackground.js plugin right before the </body> tag.

<script src="" 
<script src="jquery.convertToBackground.min.js"></script>

3. Call the function on the container element and specify the height/width of the cropped image.

  width: 500,
  height: 500

4. Keep the aspect ratio on window resize.

  responsive: true

5. Customize the CSS background properties.

  repeat: 'no-repeat',
  position: 'center center',
  size: 'cover',
  attachment: ''

6. Define the path to the fallback image.

  fallbackSrc: ''

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