admin管理员组文章数量:1221786
Is it possible to have the box-shadow
adjust its color value, based on the colors in the image it's being applied to?
If you look at abduzeedo's site, you will notice that the images all have unique box-shadow
colors, often related to their parent image (pictured below).
I did notice that the CSS is being inserted in-line into the HTML, which says to me this is done through scripting, but how? Are these colors actually being pulled from their images or are they arbitrarily/manually generated?
I've tried searching for this on Google, but I'm not having much luck. I'm not asking for a tutorial, mostly just what this is called, how to find it, or if it's even possible to do it dynamically, rather than randomly or manually.
Is it possible to have the box-shadow
adjust its color value, based on the colors in the image it's being applied to?
If you look at abduzeedo's site, you will notice that the images all have unique box-shadow
colors, often related to their parent image (pictured below).
I did notice that the CSS is being inserted in-line into the HTML, which says to me this is done through scripting, but how? Are these colors actually being pulled from their images or are they arbitrarily/manually generated?
I've tried searching for this on Google, but I'm not having much luck. I'm not asking for a tutorial, mostly just what this is called, how to find it, or if it's even possible to do it dynamically, rather than randomly or manually.
Share Improve this question asked Aug 19, 2016 at 15:24 ManlyManly 3793 silver badges18 bronze badges 3- stackoverflow.com/questions/7332573/… – Paulie_D Commented Aug 19, 2016 at 15:28
- I googled and found this: stackoverflow.com/questions/2541481/… – Daniel Commented Aug 19, 2016 at 15:28
- They are using Vibrant.js – Adam Azad Commented Aug 19, 2016 at 15:29
2 Answers
Reset to default 13Simplest approach would be to duplicate an image over other (using position: absolute;
), like two layers, one over another, and then apply filter: blur(16px);
on background image.
Checkout: Codepen-demo
You need to use JavaScript for this as you mention. There are a few different options of plug-ins that you can use but the two most populare are:
- Color Thief
- VibrantJS
Extract the dominant color of the image, and apply an inline box-shadow
style with that color on the particular element.
本文标签: javascriptBox shadow color based on colors from imageStack Overflow
版权声明:本文标题:javascript - Box shadow color based on colors from image? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739267709a2155674.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论