Change Animation speed on hover(更改悬停时的动画速度)
问题描述
我正在构建一个行星系统,它可以悬停在轨道上并且动画速度会发生变化.
我用 onMouseOver 和 .hover
jquery 进行了尝试,但我不知道为什么它不起作用.
I'm building a planetsystem, where it is possible to hover over the orbit and the animation speed changes.
I tried it with the onMouseOver and .hover
jquery, but I couldn't figure out why it wasnt working.
#universum-planet1 {
position: absolute;
height: 250px;
width: 250px;
top: 40%;
left: 50%;
margin-left: -125px;
margin-top: -65px;
z-index: 1;
border: 1px solid #989898;
-webkit-border-radius: 225px;
-moz-border-radius: 225px;
border-radius: 225px;
-webkit-animation: spin 15s linear infinite;
-moz-animation: spin 15s linear infinite;
animation: spin 15s linear infinite;
-moz-transform-origin: center center;
-webkit-transform-origin: center center;
transform-origin: center center;
}
#planet1 {
position: absolute;
top: 5%;
left: 5%;
height: 50px;
width: 50px;
z-index: 2;
-webkit-animation: spin 30s linear infinite;
-moz-animation: spin 30s linear infinite;
animation: spin 30s linear infinite;
-moz-transform-origin: center center;
-webkit-transform-origin: center center;
transform-origin: center center;
}
@-moz-keyframes spin {
100% {
-moz-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
<div id="universum-planet1">
<div id="planet1">
<a href="universe.html" id="enterLink">
<img class="enter" src="aHR0cDovL3dlYm1hdGhzLmZpbGVzLndvcmRwcmVzcy5jb20vMjAwOS8wMy9zb2NjZXJiYWxsMS5wbmc=" style="height:100%;" alt="IiBvbk1vdXNlT3Zlcj0="this.src="aHR0cDovL3d3dy5yc2ctc2hvcC5jb20vaW1hZ2VzL0JhbGwtUEFTVE9SRUxMSS1HaWFsbG8tRmx1by0wMDAxNC0wLmpwZw==";" onMouseOut="this.src="aHR0cDovL3dlYm1hdGhzLmZpbGVzLndvcmRwcmVzcy5jb20vMjAwOS8wMy9zb2NjZXJiYWxsMS5wbmc=""
/>
</a>
</div>
</div>
推荐答案
此解决方案使用具有相同关键帧动画(反转)的轨道包装器,它暂停/运行以更改悬停时的动画速度 :
This solution uses a wrapper for the orbit with the same keyframe animation (reversed) which pauses/runs to change the animation speed on hover :
演示
.wrapper{
position:absolute;
top:40%; left:50%;
margin-left:-125px;
margin-top:-65px;
width: 250px; height:250px;
-webkit-animation:spin 20s linear infinite;
-moz-animation:spin 20s linear infinite;
animation:spin 20s linear infinite;
-webkit-animation-direction: reverse;
-moz-animation-direction: reverse;
animation-direction: reverse;
-webkit-animation-play-state: paused;
-moz-animation-play-state: paused;
animation-play-state: paused;
}
#universum-planet1 {
height:250px; width: 250px;
z-index:1;
border: 1px solid #989898;
border-radius: 225px;
-webkit-animation:spin 15s linear infinite;
-moz-animation:spin 15s linear infinite;
animation:spin 15s linear infinite;
-moz-transform-origin:center center;
-webkit-transform-origin:center center;
transform-origin:center center;
}
#planet1 {
position:absolute;
top:5%; left:5%;
height: 50px; width: 50px;
z-index:2;
-webkit-animation:spin 30s linear infinite;
-moz-animation:spin 30s linear infinite;
animation:spin 30s linear infinite;
-moz-transform-origin:center center;
-webkit-transform-origin:center center;
transform-origin:center center;
}
.wrapper:hover{
-webkit-animation-play-state: running;
-moz-animation-play-state: running;
animation-play-state: running;
}
@-moz-keyframes spin { 100% { -moz-transform: rotate(360deg); } }
@-webkit-keyframes spin { 100% { -webkit-transform: rotate(360deg); } }
@keyframes spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
<div class="wrapper">
<div id="universum-planet1">
<div id="planet1"> <a href="universe.html" id="enterLink">
<img class="enter" src="aHR0cDovL3dlYm1hdGhzLmZpbGVzLndvcmRwcmVzcy5jb20vMjAwOS8wMy9zb2NjZXJiYWxsMS5wbmc=" style="height:100%;" alt="IiBvbk1vdXNlT3Zlcj0gICA="this.src="aHR0cDovL3d3dy5yc2ctc2hvcC5jb20vaW1hZ2VzL0JhbGwtUEFTVE9SRUxMSS1HaWFsbG8tRmx1by0wMDAxNC0wLmpwZw==";" onMouseOut="this.src="aHR0cDovL3dlYm1hdGhzLmZpbGVzLndvcmRwcmVzcy5jb20vMjAwOS8wMy9zb2NjZXJiYWxsMS5wbmc="" /></a>
</div>
</div>
</div>
这受到 this answer 的启发,作者为 Vals
This was inpired by this answer by Vals
这篇关于更改悬停时的动画速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:更改悬停时的动画速度


- 在不使用循环的情况下查找数字数组中的一项 2022-01-01
- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01