jQuery - 带有 hsv 色彩空间的颜色循环动画?

发布于 2024-09-05 03:14:48 字数 446 浏览 2 评论 0原文

我正在做一个项目,我需要一个特殊的身体背景。背景颜色应该像心情灯一样在色谱中循环。所以我发现了这个:

http:// buildinternet.com/2009/09/its-a-rainbow-color-changing-text-and-backgrounds/

“但是”此代码片段正在使用 RGB 色彩空间,其中包含一些非常亮和暗的颜色。获得明亮的颜色仅适用于 HSV 色彩空间(例如,将 S 和 V 静态设置为 100,然后让 H 循环)。我不知道如何转换,实际上也不知道如何根据我的需要来拉皮条这个片段。

有人有想法吗?

提前致谢。最好的,弗洛伊德

I am working on a project, which I need a special body-background for. The background-color should cycle through the color spectrum like a mood light. So I found this:

http://buildinternet.com/2009/09/its-a-rainbow-color-changing-text-and-backgrounds/

"But" this snippet is working with the RGB colorspace which has some very light and dark colors in it. Getting just bright colors will only work with the HSV colorspace (e.g. having S and V static at 100 and letting H cycle). I don’t know how to convert and in fact how to pimp this snippet for my needs.

Does anyone has an idea??

Thanks in advance. Best, Floyd

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风向决定发型 2024-09-12 03:14:48

只需使用现成的 RGB 到 HSV 转换函数,例如:

<块引用>

http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript

然后只需输入你的颜色作为HSV和你将获得可在动画中使用的 RGB。

Just use an ready made RGB to HSV conversion function, like this for example:

http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript

Then just input your color as HSV and you'll get RGB that you can use in your animations.

伏妖词 2024-09-12 03:14:48

ColorJizz 应该就是您所需要的。

ColorJizz should be what you need.

み格子的夏天 2024-09-12 03:14:48

我相信这就是您想要的效果。 randRange() 函数允许您指定最小值和最大值。

<script language="JavaScript" type="text/javascript">
function randRange(lowVal,highVal) {
     return Math.floor(Math.random()*(highVal-lowVal+1))+lowVal;
}
function spectrum(){  
    var hue = 'rgb(' + randRange(100,256) + ',' + randRange(100,256) + ',' + randRange(100,256) + ')';  
    $('#div').animate( { backgroundColor: hue }, 1000);  
    spectrum();  
 }  
$(function(){
    spectrum();
});
</script>

I believe that this is the effect you were looking for. The randRange() function allows you to specify a minimum and maximum value.

<script language="JavaScript" type="text/javascript">
function randRange(lowVal,highVal) {
     return Math.floor(Math.random()*(highVal-lowVal+1))+lowVal;
}
function spectrum(){  
    var hue = 'rgb(' + randRange(100,256) + ',' + randRange(100,256) + ',' + randRange(100,256) + ')';  
    $('#div').animate( { backgroundColor: hue }, 1000);  
    spectrum();  
 }  
$(function(){
    spectrum();
});
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文