Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (function ($) {
- $(document).ready(function () {
- $('.image-to-colour').each(function (index, element) {
- var images = $(this).find('img');
- if (images.length == 1) {
- var imageColours = getImageColours(images[0]);
- element.style.color = imageColours.textColour;
- element.style.backgroundColor = imageColours.backgroundColour;
- }
- });
- });
- // Get suitable background and foreground colours from image
- function getImageColours(image) {
- var vibrant = new Vibrant(image);
- var swatches = vibrant.swatches();
- return {
- backgroundColour: (swatches.LightMuted) ? swatches.LightMuted.getHex() : ((swatches.LightVibrant) ? swatches.LightVibrant.getHex() : '#fff'),
- textColour: (swatches.LightMuted) ? swatches.LightMuted.getTitleTextColor() : ((swatches.LightVibrant) ? swatches.LightVibrant.getTitleTextColor() : '#000')
- }
- }
- })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement