html - 悬停在css中时如何停止自动滚动动画?
问题描述
我是初学者,也是第一次使用动画和转换。当我将鼠标悬停在“此处的一些文本”上时,我试图停止动画,但我没有得到正确的输出,可能是因为 &:hover 的位置不准确或错误,请帮助解决这个问题。
#contentwrapper {
height: 190px;
background-color: tomato;
overflow-y: hidden;
}
#inner-wrapper {
animation: autoscroll 10s linear infinite;
}
@keyframes autoscroll {
&:hover {
animation-play-state: paused;
}
from {
transform: translate3d(0, 0, 0);
}
to {
transform: translate3d(0, -90%, 0);
}
}
<div id="contentwrapper">
<div id="inner-wrapper">
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
</div>
</div>
解决方案
您可以:hover
在元素本身上使用:
#contentwrapper {
height: 190px;
background-color: tomato;
overflow-y: hidden;
}
#inner-wrapper {
animation: autoscroll 10s linear infinite;
}
#inner-wrapper:hover{
animation-play-state: paused;
}
@keyframes autoscroll {
from {
transform: translate3d(0,0,0);
}
to {
transform: translate3d(0,-90%,0);
}
}
<div id="contentwrapper">
<div id="inner-wrapper">
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
<div><a href="#">some text here</a></div>
</div>
</div>
推荐阅读
- angular - 使用 Angular cli 7 在生产包中添加延迟/异步
- javascript - 使用 jQuery-Ajax REST API 调用的 iframe 显示不完整的页面
- php - PHPSpreadsheet - 如何将链接中的图像放入我的 excel 文件中?
- reactjs - ReactJS API 调用:未处理的拒绝(TypeError):无法读取未定义的属性“映射”
- apache - Apache 正在下载 fcgi
- firebase - 如何进行 Firebase 聊天分页?
- angular - Angular 自定义表单控件 - 使用 selectionChange 事件对 mat-select 进行更改检测
- c++ - OpenCV C++ 查找轮廓并获取像素值
- google-chrome-extension - 如何避免 chrome web 扩展中的跨域读取阻塞(CORB)
- react-native - 在 react native 中将完整的 android 项目导出到 iOS 的可能性