在CSS中如何用animation做轮播图的效果
Admin 2022-07-30 群英技术资讯 841 次浏览
实现思路
1、通过animation达到动起来的效果,具体变化似乎有两种可行方式:
2、在动画中,通过CSS-transform不断平移轮播图元素位置。
3、在动画中,设置不同的left值。
实现效果与代码
其中值得注意的点在于需要手动在轮播图头部添加最后一张图的复制,否则会有明显的闪动效果。
实例
<!DOCTYPE html> <body> <div style="flex: 1;height: 300px;z-index: 10;box-shadow: inset 0 0 300px rgba(0, 0, 0, 0.99);"> left </div> <div class="showbox border box-shadow"> <div class="left border"> 左 </div> <div class="right border"> 右 </div> <div id="imgbox" class="center imgbox"> <img src="https://cdn.pixabay.com/photo/2018/01/03/05/33/the-sun-3057622__340.jpg" /> <img src="https://cdn.pixabay.com/photo/2021/07/29/20/23/mountains-6508015_960_720.jpg" /> <img src="https://cdn.pixabay.com/photo/2021/07/29/21/03/cereals-6508088__340.jpg" /> <img src="https://cdn.pixabay.com/photo/2018/01/03/05/33/the-sun-3057622__340.jpg" /> </div> </div> <div style="flex: 1;height: 300px;z-index: 10;box-shadow: inset 0 0 300px rgba(0, 0, 0, 0.99);" > right </div> </body> <!-- <script> let a = 0 let max = 300 * 3; window.onload = function() { refresh(); } function refresh() { document.getElementById("imgbox").style.left = a + "px"; } function left() { a = (a-300)%max; refresh(); } function right () { a = (a+300)%max; refresh(); } </script> --> <style> body { width: 100%; height: 100%; z-index: 0; /* background-color: rgba(0, 0, 0, 0.5); */ box-shadow: inset 0 0 300px rgba(0, 0, 0, 0.1); } .center { display: flex; flex-direction: row; align-items: center; justify-content: center; } .showbox { width: 300px; height: 300px; /* background: chocolate; */ position: relative; overflow: visible; display: flex; flex-direction: row; align-items: center; justify-content: center; /* z-index: -1; */ opacity: 1; } .left { position: absolute; left: 0; top: 50%; cursor: pointer; background: blue; z-index: 100; } .right { position: absolute; right: 0; top: 50%; cursor: pointer; background: blue; z-index: 100; } .border { border: 1px solid black; } .centerimg { width: 100%; height: 100%; } .myimg { width: 300px; height: 300px; z-index: -1; opacity: 1; /* filter: alpha(opacity=60); */ } .imgbox { position: absolute; left: -600px; top: 0; z-index: -1; animation: slideshow 10s both infinite; } @keyframes slideshow { 0% { left: -900px; } 33% { left: -600px; } 66% { left: -300px; } 100% { left: 0; } } </style> </html>
本文教程操作环境:windows7系统、css3版,DELL G3电脑。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
大型项目往往会使用构建工具搭建工程。构建工具允许将css样式切分为更加精细的模块。冲突的类名往往发生在不同的css模块文件中,只需要保证构建工具在合并样式代码后不会出现类名冲突即可。
有很多网站都会使用时间轴动画,其好处就是就是可以直观展示时间线以及美化网站,那么时间轴动画效果是如何实现的呢?下面分享一个CSS3实现时间轴动画的实例,效果图如下,感兴趣的朋友就继续往下看吧。
css px和pt的不同:1、px和pt,一个是设备坐标,一个是逻辑坐标,两者不同。2、pt是绝对单位,1pt=1/72英寸。px是一个相对单位。用px定义文本,不管用户如何设置,大小都不会改变。
什么时候可以使用 !important ,规则1.覆盖内联样式2.覆盖优先级很高的选择器三、禁用 !important 的经验法则一、理解 !important
这篇文章主要介绍了canvas绘制太极图的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008