CSS 字符串 –选择第三个逗号之前的所有内容
我正在使用 Scriptaculous 编写一个自定义突出显示动画,其中包括 CSS3 发光。我得到了 box-shadow 样式,需要在 rgba alpha 值处分割它,然后改变该值以使阴影淡出。
$('fresh').style.MozBoxShadow
将返回
0 0 20px rgba(163, 238, 71, 1.0)
1.0
是 alpha 值。我需要将其拆分,以便可以设置:
$('fresh').style.MozBoxShadow = everythingBeforeAlphaValue + anAlphaValueIVaryWithJS + ')';
所有数字都可以是任意位数的长度,因此我不能使用 substring
(这就是我真正知道的:))。你能帮忙吗?
I'm writing a custom highlight animation with Scriptaculous that includes a CSS3 glow. I get the box-shadow style and need to split it at the rgba alpha value, then vary that value to get the shadow to fade.
$('fresh').style.MozBoxShadow
would return
0 0 20px rgba(163, 238, 71, 1.0)
1.0
is the alpha value. I need to split it so that I can set:
$('fresh').style.MozBoxShadow = everythingBeforeAlphaValue + anAlphaValueIVaryWithJS + ')';
All the numbers can be any number of digits long, so I can't use substring
(and that's all I really know :) ). Can you help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,你仍然可以使用
substring
,因为你可以知道lastIndexOf(',')
,例如:Well, you can still use
substring
, because you can know thelastIndexOf(',')
, for example:以编程方式完成会更好、更干净,无需解析字符串。
如果我正确理解 逻辑,您应该能够到达直接通过颜色
即可节省一部分。
我也很确定可以通过编程方式访问颜色的“alpha”分量,但我不知道如何。
This would be better and cleaner done programmatically, without parsing a string.
If I understand the logic right, you should be able to reach the colour directly via
That'll save you one part of it.
I'm also quite sure it is possible to access the "alpha" component of a colour programmatically, but I don't know how.