[英]Changing a css attribute starting with a dash using Javascript
我正在尝试使用通常的方法通过javascript更改css属性。 问题是基于Webkit的属性以破折号开头,从而使javascript无效。
document.getElementById('circle1').style.-webkit-animation = 'upDown 15s infinite';
我如何修改此代码才能有效。
参考这个问题 :
test.style.webkitAnimationName = 'colorchange'; // you had a trailing space here which does NOT get trimmed
test.style.webkitAnimationDuration = '4s';
document.getElementById('circle1').style['-webkit-animation'] = 'upDown 15s infinite';
您可以使用.setAttribute()
:
document.getElementById('circle1').setAttribute("style", "-webkit-animation: upDown 15s infinite");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.