时间:2021-07-01 10:21:17 帮助过:5人阅读
html代码:
- <div class="panorama"></div>
首先定义一些基本的样式和动画:
- .panorama {
- width: 300px;
- height: 300px;
- background-image: url(http://7vilbi.com1.z0.glb.clouddn.com/blog/6608185829213862083.jpg);
- background-size: auto 100%;
- cursor: pointer;
- animation: panorama 10s linear infinite alternate;
- }
- @keyframes panorama {
- to {
- background-position: 100% 0;
- }
- }
background-size: auto 100%;
这段代码的意思是让图片的高等于容器的高,并且水平方向自动,即图片最左边贴着容器左侧。
执行动画的流程是:周而复始、往复交替、线性并且时间周期是10s。
现在我们实现当鼠标悬浮于图片时才让它动起来,鼠标离开让它静止。
需要用到这个属性animation-play-state: paused | running
,它表示动画的两个状态:暂停
和运行
。
完整CSS代码:
- .panorama {
- width: 300px;
- height: 300px;
- background-image: url(http://7vilbi.com1.z0.glb.clouddn.com/blog/6608185829213862083.jpg);
- background-size: auto 100%;
- cursor: pointer;
- animation: panorama 10s linear infinite alternate;
- animation-play-state: paused;
- }
- .panorama:hover,
- .panorama:focus {
- animation-play-state: running;
- }
- @keyframes panorama {
- to {
- background-position: 100% 0;
- }
- }
相关推荐:
如何使用纯CSS3实现图片轮播的效果
如何使用纯CSS实现彩虹条纹文字的效果(附代码)
以上就是CSS3如何实现全景图的动画效果(附代码)的详细内容,更多请关注Gxl网其它相关文章!