作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个脚本,使用 color-thief.js 从图像中获取主色,然后将该颜色用作背景色。我以前从未使用过这个插件,所以我不知道我到底做错了什么。但是背景颜色没有应用。
$(document).ready(function($) {
$(".box img").load(function(){
var dominantColor = getDominantColor($(this));
$(this).parent().css("background-color", "rgb("+dominantColor+")");
});
});
提前致谢。
最佳答案
您需要启动 ColorThief 对象以引用其内部方法。
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+")");
});
});
关于javascript - 使用 color-thief 从图像中获取背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25329648/
我正在编写一个脚本,使用 color-thief.js 从图像中获取主色,然后将该颜色用作背景色。我以前从未使用过这个插件,所以我不知道我到底做错了什么。但是背景颜色没有应用。 $(document)
使用 Color Thief javascript 效果,我写了一些代码来获取图像的主色并根据图像调整整个主题的配色方案。 这一切都适用于单个产品页面,其中只使用了一个图像。在我的目录页面上,有多个图
我已经使用了 bootstrap carousal 并且能够仅使用一张图像的 color thief 更改 header background 的颜色。 但是在 carousal 中有多个图像随时间变
我是一名优秀的程序员,十分优秀!