Angular Adaptive Backgrounds
Surround a picture with its dominant color using a simple directive
$ npm install --save angular-adaptive-backgrounds
the lowdown
This directive is essentially extracting the dominant color from an image and applying that color to its parent's background. Here's the most simple example:
<!-- Load the script after AngularJS -->
// Make sure your app depends on this modulevar myApp = angular;
<!-- This guy will get receive a background color... --> <!-- from this image -->
getting fancy
Since your markup could get far more complicated in a real example, adaptive-background
will dig through its descendents for the first img
it can find.
choose an image
But if you have multiple images descending from your adaptive-background
, it might find the wrong one! Fortunately, you can specify a class name.
<!-- It will skip right past this image --> <!-- and grab a color from this image -->
In certain cases, you might want to specify a class name for your entire app, instead of repeatedly setting ab-image-class
.
myApp;
<!-- Even without setting ab-image-class... --> <!-- it will still find this image -->
css background-image
Instead of an img
element, you might have a background-image
on some other element. Have no fear. Simply ensure you've set a parent class, either by ab-image-class
or a global config
.
classes
If you have text overlaying the background color, that text might no longer be readable. You have a couple classes to work with though.
ab-light-background
will be applied to a lighter background and, as you might expect, ab-dark-background
on a darker background. You could do something like this to make sure your text contrasts with the background.
If you're displeased with those class names, feel free to change them.
myApp;
dev
$ npm install$ npm start