[英]JavaScript DOM Animation Border Color
I have a small problem about editing the border color of an animation.我有一个关于编辑动画边框颜色的小问题。
I tried using我尝试使用
document.getElementById("ID").style.animationName = "YellowBorder";
And I declared YellowBorder as :我宣布 YellowBorder 为:
<style>
YellowBorder {
@keyframes animate-border {
0% {border-color: #000000;}
100% {border-color: #FFFF00;}
}
}
</style>
I know this is wrong and for it to work it should be:我知道这是错误的,它应该是:
<style>
@keyframes animate-border {
0% {border-color: #000000;}
100% {border-color: #FFFF00;}
}
</style>
But if I do this, it'll just become yellow before using any JavaScript code even if I put it on a但是如果我这样做,它会在使用任何 JavaScript 代码之前变成黄色,即使我把它放在
<script> If (condition) { <style> **HERE** </style> } </script>
So i found an answer using a bit of my knowledge : I had to create the style as a Javascript variable.所以我使用我的一些知识找到了一个答案:我必须将样式创建为 Javascript 变量。
var Yellow = "@keyframes animate-border{ 0%{border-color: #000000;} 100%{border-color: #FFFF00;} }";
and then create a Style element :然后创建一个 Style 元素:
var s = document.createElement("style");
Now we want that style to contain our "Yellow" inside it:现在我们希望该样式在其中包含我们的“黄色”:
s.innerHTML = Yellow;
and Finally using this command to apply the style inside our web page :最后使用此命令在我们的网页中应用样式:
document.getElementsByTagName("head")[0].appendChild(s);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.