Advertisement
Guest User

Untitled

a guest
Jun 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. (function ($) {
  2. $(document).ready(function () {
  3. $('.image-to-colour').each(function (index, element) {
  4. var images = $(this).find('img');
  5. if (images.length == 1) {
  6. var imageColours = getImageColours(images[0]);
  7. element.style.color = imageColours.textColour;
  8. element.style.backgroundColor = imageColours.backgroundColour;
  9. }
  10. });
  11. });
  12.  
  13. // Get suitable background and foreground colours from image
  14. function getImageColours(image) {
  15. var vibrant = new Vibrant(image);
  16. var swatches = vibrant.swatches();
  17. return {
  18. backgroundColour: (swatches.LightMuted) ? swatches.LightMuted.getHex() : ((swatches.LightVibrant) ? swatches.LightVibrant.getHex() : '#fff'),
  19. textColour: (swatches.LightMuted) ? swatches.LightMuted.getTitleTextColor() : ((swatches.LightVibrant) ? swatches.LightVibrant.getTitleTextColor() : '#000')
  20. }
  21. }
  22. })(jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement