html – CSS3动画钟摆效果

html – CSS3动画钟摆效果,第1张

概述我想用纯CSS制作钟摆效果,但它并不流畅. 这是我想要的,但纯CSS. http://www.webdevdoor.com/demos/html5-pendulum-demo/ 但我更喜欢根据它的位置看起来更像自然的速度变化. Fiddle .bellImg { height: 20px; width: 20px; position: absolute; right: 10px; 我想用纯CSS制作钟摆效果,但它并不流畅.

这是我想要的,但纯CSS. http://www.webdevdoor.com/demos/html5-pendulum-demo/

但我更喜欢根据它的位置看起来更像自然的速度变化.

Fiddle

.bellimg {  height: 20px;  wIDth: 20px;  position: absolute;  right: 10px;  top: 18px;  -webkit-animation-name: rotate;  animation-delay: 3s;  -webkit-animation-duration: 2s;  -webkit-animation-iteration-count: infinite;  -webkit-animation-direction: linear;  -webkit-transform-origin: 50% 0%;  -webkit-animation-timing-function: ease-in-out;}@-webkit-keyframes rotate {  0% {    -webkit-transform: rotate(0deg);  }  10% {    -webkit-transform: rotate(10deg);  }  20% {    -webkit-transform: rotate(20deg);  }  30% {    -webkit-transform: rotate(10deg);  }  40% {    -webkit-transform: rotate(5deg);  }  50% {    -webkit-transform: rotate(0deg);  }  60% {    -webkit-transform: rotate(-5deg);  }  70% {    -webkit-transform: rotate(-10deg);  }  80% {    -webkit-transform: rotate(-20deg);  }  90% {    -webkit-transform: rotate(-10deg);  }  100% {    -webkit-transform: rotate(0deg);  }}
<img  src="img/bell.png">
解决方法 您的代码中存在一些问题:

> animation-timing-function被指定为easy-in-out.这表示动画开始和结束缓慢,但两者之间的速度更快.为了优雅和平等的移动,这应该设置为线性.

This is what 07001:

This keyword represents the timing function cubic-bezIEr(0.42,0.0,0.58,1.0). With this timing function,the animation starts slowly,accelerates then slows down when approaching its final state. At the beginning,it behaves similarly to the ease-in function; at the end,it is similar to the ease-out function.

> animation-direction没有名为linear的值.
>分裂不相等.也就是说,对于大约10%的间隙,它旋转10度,而对于其他间隙,它仅旋转5度.使分裂相等.

完成所有更正的以下片段可生成平滑的动画.

.bellimg {  height: 20px;  wIDth: 20px;  position: absolute;  right: 10px;  top: 18px;  -webkit-animation-name: rotate;  animation-delay: 3s;  -webkit-animation-duration: 2s;  -webkit-animation-iteration-count: infinite;  -webkit-animation-direction: normal;  -webkit-transform-origin: 50% 0%;  -webkit-animation-timing-function: linear;  /* or make your custom easing */}@-webkit-keyframes rotate {  0% {    -webkit-transform: rotate(0deg);  }  25% {    -webkit-transform: rotate(20deg);  }  75% {    -webkit-transform: rotate(-20deg);  }  100% {    -webkit-transform: rotate(0deg);  }}
<img  src="https://cdn1.iconfinder.com/data/icons/freeline/32/bell_sound_notification_remind_reminder_ring_ringing_schedule-48.png">

设置动画的速度取决于位置(即,当它到达极端时减速并在中间加速)是不可能用纯CSS实现的(即使我们添加了额外的元素).

要根据其位置设置动画的速度,可以选择执行以下 *** 作:

>将图像添加到容器元素中.对其进行动画处理,使其从20deg旋转到-40deg.
>使父项上的动画早于子项的动画持续时间的1/3.也就是说,减少父母的延迟0.66秒.这样做是为了让父母偏移孩子的初始轮换.差异是动画持续时间的1/3,因为它是父母到达0deg所花费的时间.
>更改图像动画的关键帧,使旋转从-20deg到40deg.
>将动画方向设置为两者的替代,以便它们在前向进行第一次迭代,反向进行下一次,依此类推.
>将animation-timing-function设置为easy-in-out,以便在接近极限时减慢速度.当动画持续时间增加时,效果更明显.

.container {  position: absolute;  height: 20px;  wIDth: 20px;  /* right: 10px; commented for demo */  top: 18px;  transform: rotate(20deg);  animation-name: rotate-container;  animation-delay: 2.33s;  animation-duration: 2s;  animation-iteration-count: infinite;  animation-direction: alternate;  transform-origin: 50% 0%;  animation-timing-function: ease-in-out;}.bellimg {  height: 100%;  wIDth: 100%;    transform: rotate(-20deg);  animation-name: rotate;  animation-delay: 3s;  animation-duration: 2s;  animation-iteration-count: infinite;  animation-direction: alternate;  transform-origin: 50% 0%;  animation-timing-function: ease-in-out;}@keyframes rotate {  0% {    transform: rotate(-20deg);  }  100% {    transform: rotate(40deg);  }}@keyframes rotate-container {  0% {    transform: rotate(20deg);  }  100% {    transform: rotate(-40deg);  }}
<script src="https://cdnjs.cloudflare.com/AJAX/libs/prefixfree/1.0.7/prefixfree.min.Js"></script><div class='container'>  <img  src="https://cdn1.iconfinder.com/data/icons/freeline/32/bell_sound_notification_remind_reminder_ring_ringing_schedule-48.png"></div>

代码段中仅使用无前缀库来避免浏览器前缀.

总结

以上是内存溢出为你收集整理的html – CSS3动画钟摆效果全部内容,希望文章能够帮你解决html – CSS3动画钟摆效果所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1084940.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存