Reputation: 169
I am working on a script to grab the dominant color from an image using color-thief.js and then use that color as background-color. I have never used this plugin before so I don't know what I am exactly doing wrong. The background color is not applying though.
$(document).ready(function($) {
$(".box img").load(function(){
var dominantColor = getDominantColor($(this));
$(this).parent().css("background-color", "rgb("+dominantColor+")");
});
});
Thanks in advcance.
Upvotes: 2
Views: 2586
Reputation: 1538
You need to initiate the ColorThief object to reference its internal methods.
var colorThief = new ColorThief();
$(document).ready(function($) {
$(".box img").load(function(){
var dominantColor = colorThief.getColor($(this));
console.log(dominantColor);
$(this).parent().css("background-color", "rgb("+dominantColor+")");
});
});
Upvotes: 2