A simple jQuery plugin to extract the dominant color of an image and apply it to the background of its parent element.
Simply include jQuery and the script in your page, then run the script like so:
$(document).ready(function(){
$.adaptiveBackground.run()
});
The script looks for image(s) with the data-adaptive-background
attribute:
<img src="/image.jpg" data-adaptive-background='1'>
This plugin exposes one method:
- $.adaptiveBackground.run(opts) arg: opts (Object) an optional argument to be merged in with the defaults.
- selector String (defult: 'img[data-adaptive-background="1"]') a CSS selector which denotes which images to grab/process. Ideally, this selector would start with img, to ensure we only grab and try to process actual images.
- parent String (defult: 'img[data-adaptive-background="1"]') a string which denotes which images to grab. Ideally, this selector would start with img, to ensure we only grab and try to process images.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ullamcorper justo sem. Fusce ac sem est. Aenean dignissim feugiat auctor. Vestibulum in ante sem. Ut sit amet erat arcu, eget fringilla odio. Aenean a nibh est. Cras metus urna, vulputate non feugiat vel, condimentum sit amet purus.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam ullamcorper justo sem. Fusce ac sem est. Aenean dignissim feugiat auctor. Vestibulum in ante sem. Ut sit amet erat arcu, eget fringilla odio. Aenean a nibh est. Cras metus urna, vulputate non feugiat vel, condimentum sit amet purus.
lipsum.
Lipsum.