徘徊时,如何减慢变换并防止元素的转移?
我正在尝试创建一个悬停时会减慢的选选。
我设法使“放慢脚步”分类,但是由于某种原因,徘徊时的元素会发生变化。
我四处搜索并了解它可能与变换原点有关,但无法弄清楚什么。
- 预期行为:元素不会改变,并且会优雅地减慢(如果有道理)。
提前致谢!
<div class="wrapper">
<div class="track">
<div class="content">
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
</div>
</div>
CSS
<style lang="scss">
:root {
--animationTiming: 100s;
}
.wrapper {
position: relative;
width: 100vw;
max-width: 100%;
height: 200px;
overflow: hidden;
}
.track {
position: absolute;
white-space: nowrap;
will-change: transform;
animation: marquee var(--animationTiming) linear infinite;
&:hover {
--animationTiming: 120s;
transition: cubic-bezier(0.47, 0, 0.745, 0.715);
transition-duration: 3s;
transition: transform 500ms ease-in-out 25ms;
transform-origin: top right;
}
}
@keyframes marquee {
from {
transform: translateX(0);
}
to {
transform: translateX(-50%);
}
}
.content {
display: flex;
}
.box {
width: 500px;
height: 500px;
background-color: red;
border: 1px solid #000;
}
</style>
I'm trying to create a Marquee that slows down when hovered on.
I managed to get the "slowing down" sorted, but for some reason, the elements shift when hovered on.
I searched around and understand it probably has something to do with transform origin, but just can't figure out what.
- Expected behavior: elements do not shift, and gracefully slows down (if that makes sense).
Thanks in advance!
<div class="wrapper">
<div class="track">
<div class="content">
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
<div class="box" />
</div>
</div>
CSS
<style lang="scss">
:root {
--animationTiming: 100s;
}
.wrapper {
position: relative;
width: 100vw;
max-width: 100%;
height: 200px;
overflow: hidden;
}
.track {
position: absolute;
white-space: nowrap;
will-change: transform;
animation: marquee var(--animationTiming) linear infinite;
&:hover {
--animationTiming: 120s;
transition: cubic-bezier(0.47, 0, 0.745, 0.715);
transition-duration: 3s;
transition: transform 500ms ease-in-out 25ms;
transform-origin: top right;
}
}
@keyframes marquee {
from {
transform: translateX(0);
}
to {
transform: translateX(-50%);
}
}
.content {
display: flex;
}
.box {
width: 500px;
height: 500px;
background-color: red;
border: 1px solid #000;
}
</style>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论