使用keyframes无法使block元素移动的问题求助
解决@keyframes无法让元素移动的问题
你的代码里有个明显的拼写错误,导致动画不生效:
animation: block is infinite linear;里的is是笔误,应该改成动画时长,比如1s(代表1秒完成一次动画),浏览器无法识别is这个无效值,所以元素不会动。
修正后的完整代码:
#block{ width: 20px; height: 20px; background-color: blue; position: relative; top: 130px; left: 480px; animation: block 1s infinite linear; } @keyframes block{ 0%{left:480px;} 100%{left: -40px;} }
其他部分的写法是正确的:设置position: relative让元素可以通过left属性移动,@keyframes的关键帧定义也没问题,修正后元素就能正常从左向右移动并循环了。
内容的提问来源于stack exchange,提问作者Cheems Bread
相关产品推荐
相关产品推荐

