【发布时间】:2017-04-05 06:03:35
【问题描述】:
我做了这个 http://codepen.io/adamchenwei/pen/dOvJNX
我尝试为 dom 应用某种移动方式,使其移动固定距离并停止,而不是动画并移动穿过 dom 的整个宽度。但是,我真的不想修复 css keyframe 内的距离,因为我需要动态检测该距离,因为我的理想动画的 div 也会动态改变宽度,因为这并不总是 100%或任何特定的px 已修复。
有没有办法我可以在 JavaScript 中做到这一点,而不是让 css 负责这个变换距离部分? 跨浏览器容量会很大。
SCSS
.myItem {
height: 100px;
width: 501px;
background-color: beige;
animation: to-left-transition 300ms;
animation-iteration-count: 1;
animation-fill-mode: forwards;
animation-timing-function: ease-in-out;
}
@keyframes to-left-transition {
0% {
transform: translate(0);
}
100% {
transform: translate(100%);
}
}
HTML
<div class="myItem">
stuff here
</div>
【问题讨论】:
-
请在问题本身的minimal reproducible example 中提供所有相关代码,而不是在第三方网站上。
-
@MikeMcCaughan 谢谢完成
标签: javascript css css-animations css-transforms keyframe