如何解决使用JavaScript更改动画的字体大小
我想使用CSS动画更改HTML元素的字体大小,同时使该元素摇动。
我的代码:
function setZeroScore(){
var score = document.querySelector('#current-'+activePlayer);
score.animate([
// keyframes
{ transform: 'translate(1px,1px)' },{ transform: 'translate(-1px,-2px)'},{ transform: 'translate(-3px,0px)' },{ transform: 'translate(3px,2px)' },{ transform: 'translate(1px,-1px)' },-2px)' }
],{
// timing options
duration: 750,});
}
它可以很好地震动,但是当我尝试此操作时出现错误:
function setZeroScore(){
var score = document.querySelector('#current-'+activePlayer);
score.animate([
// keyframes
{ transform: 'translate(1px,1px)',font-size:25px },-2px)',0px)',2px)',-1px)',font-size:25px }
],});
}
解决方法
这是因为font-size
不是属性的有效名称。破折号(-
)也可以用作subtraction operator,并以font - size
的形式读取属性名称。尽管将属性名称识别为元素的字体大小,但是将属性名称设置为字符串将使其有效('font-size':
)。
JavaScript使用camelCases作为此类名称。
另外25px
应该是字符串。
{ transform: 'translate(1px,1px)',fontSize: '25px' },
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。