in jQuery

Adaptive Backgrounds jQuery Plugin

I recently found a good resource for changing the background colour of a containing div. This is a jQuery plugin that will search for the most dominating colour in an image and will change it's containing element background to this colour. Allowing you to create some nice looking showcase pages with just a few lines of Javascript. This plugin is called the jQuery Adaptive Background Plugin. adaptive-background To use this jQuery plugin all you have to do is have a page with a number of images on it wrapped around a div like this.

<div class="page-slide">
    <img src="./images/water.jpg" alt="Water" data-adaptive-background='1'/>
<div class="page-slide">
    <img src="./images/water2.jpg" alt="Water 2" data-adaptive-background='1'/>
<div class="page-slide">
    <img src="./images/water3.jpg" alt="Water 3" data-adaptive-background='1'/>
<div class="page-slide">
    <img src="./images/water4.jpg" alt="Water 4" data-adaptive-background='1'/>
<div class="page-slide">
    <img src="./images/water5.jpg" alt="Water 5" data-adaptive-background='1'/>

When the plugin is ran it will search for images which have an attribute of data-adaptive-background and will find the dominate colour in these images. To setup the Javascript to use the following you first need to download the plugin from the Github project page. Adaptive Background Plugin Because this is a JQuery plugin it relies on jQuery being loaded on the page before you can use it.

<script src=""></script>
<script src="./js/jquery.adaptive-backgrounds.js"></script>

With the adaptive background plugin loaded on the page all we have to do is run the adaptiveBackground method to start the plugin.


Now you will see all the wrapper div will have a new background colour of the dominate colour in the image. View the demo to see how this works. Demo

Upgrade to access all content on Paulund

Members unlock all tutorials and snippets

Access to all downloadable content

Access to code examples before others

Sign Up Now

Already a member? Login here

Subscribe To The Weekly Newsletter

Get weekly updates to your email