最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - Changing a css attribute starting with a dash using Javascript - Stack Overflow

programmeradmin2浏览0评论

I'm trying to use the ussual method of changing a css property with javascript. The problem is that the webkit based attributes start with a dash making the javascript invalid.

document.getElementById('circle1').style.-webkit-animation = 'upDown 15s infinite';

How can I modify this code to be valid.

I'm trying to use the ussual method of changing a css property with javascript. The problem is that the webkit based attributes start with a dash making the javascript invalid.

document.getElementById('circle1').style.-webkit-animation = 'upDown 15s infinite';

How can I modify this code to be valid.

Share Improve this question asked Jun 18, 2014 at 3:46 Philip KirkbridePhilip Kirkbride 22.9k39 gold badges131 silver badges237 bronze badges 0
Add a ment  | 

3 Answers 3

Reset to default 3

Refer to this question:

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';

You can use .setAttribute():

document.getElementById('circle1').setAttribute("style", "-webkit-animation: upDown 15s infinite");
发布评论

评论列表(0)

  1. 暂无评论