当前位置: 首页 > news >正文

纯css 轮播图片,鼠标移入暂停 移除继续

核心

滚动:
animation: 动画名称 20s linear infinite normal;停止:
animation: 动画名称 20s linear infinite paused;

完整例子:

html:

<div class="carousel-wrapper"><div class="carousel"><div class="item"><img src="https://logo.clearbit.com/apple.com" alt="apple"></div><div class="item"><img src="https://logo.clearbit.com/google.com" alt="Google"></div><div class="item"><img src="https://logo.clearbit.com/amazon.com" alt="Amazon"></div><div class="item"><img src="https://logo.clearbit.com/microsoft.com" alt="Microsoft"></div><div class="item"><img src="https://logo.clearbit.com/facebook.com" alt="Facebook"></div><div class="item"><img src="https://logo.clearbit.com/netflix.com" alt="Netflix"></div><div class="item"><img src="https://logo.clearbit.com/tesla.com" alt="Testla"></div><div class="item"><img src="https://logo.clearbit.com/nike.com" alt="Nike"></div><div class="item"><img src="https://logo.clearbit.com/adidas.com" alt="Addidas"></div><div class="item"><img src="https://logo.clearbit.com/coca-cola.com" alt="Coca-Cola"></div>
<!-- we need to add duplicate elements to make up the space - this needs to be magic numbered according to size of elements and width of container --><div class="item"><img src="https://logo.clearbit.com/apple.com" alt="apple"></div><div class="item"><img src="https://logo.clearbit.com/google.com" alt="Google"></div><div class="item"><img src="https://logo.clearbit.com/amazon.com" alt="Amazon"></div><div class="item"><img src="https://logo.clearbit.com/microsoft.com" alt="Microsoft"></div></div>
</div>

css:

*{margin: 0;padding: 0;box-sizing: border-box;
}
:root{--bg-clr: #64748B;
}
body {min-height: 100svh;display: grid;place-content: center;background-color: var(--bg-clr);
}.carousel-wrapper {--width: 100px;--gap: 0;--num-items: 10;--ani-offset: calc(var(--width) * var(--num-items) * -1);--ani-speed: 10s;width: 400px;overflow: hidden;position: relative;
}
.carousel-wrapper::before,
.carousel-wrapper::after{content: '';position: absolute;width: 20%;height: 100%;z-index: 1;top: 0;
}
.carousel-wrapper::before{left: 0;background-image: linear-gradient(to right,var(--bg-clr) 0%,transparent 50%);
}
.carousel-wrapper::after{right: 0;background-image: linear-gradient(to left,var(--bg-clr) 0%,transparent 50%);
}.carousel {display: flex;align-items: center;animation: slide var(--ani-speed) linear infinite normal;
}
.carousel:hover {animation: slide var(--ani-speed) linear infinite paused;
}
.item{flex: 1 0 var(--width);text-align: center;padding:1rem;
}
.item:last-child{/*background: red;*/
}
.item > img{width: 100%;height: auto;object-fit: cover;
}@keyframes slide {100% {transform: translateX(var(--ani-offset));}
}

http://www.lryc.cn/news/463745.html

相关文章:

  • iOS GCD的基本使用
  • 如何设计开发RTSP直播播放器?
  • Java基础系列-一文搞懂自定义排序
  • 扫普通链接二维码打开小程序
  • 计算机储存与分区
  • OpenCV之换脸技术:一场面部识别的奇妙之旅
  • Linux学习笔记9 文件系统的基础
  • Android OpenGL粒子特效
  • 5 -《本地部署开源大模型》在Ubuntu 22.04系统下ChatGLM3-6B高效微调实战
  • dpkg:错误:另外一个进程已经为dpkg前端锁加锁
  • 基于SSM服装定制系统的设计
  • RK3588开发笔记-usb3.0 xhci-hcd控制器挂死问题解决
  • 深入解析TCP/IP协议:网络通信的基石
  • 基于微信小程序的汽车预约维修系统(lw+演示+源码+运行)
  • wifi、热点密码破解 - python
  • bean的实例化2024年10月17日
  • 告别ELK,APO提供基于ClickHouse开箱即用的高效日志方案——APO 0.6.0发布
  • Excel使用技巧:定位Ctrl+G +公式+原位填充 Ctrl+Enter快速填充数据(处理合并单元格)
  • JAVA学习-练习试用Java实现“成绩归类”
  • 【Hive】7-拉链表的设计与实现
  • Maxwell 底层原理 详解
  • 使用短效IP池的优势是什么?
  • zynq烧写程序到flash后不运行
  • JMeter如何设置HTTP代理服务器?
  • React面试题笔记(一)
  • 3.Java入门笔记--基础语法
  • 关于SOCKS协议的常见误区有哪些?
  • 无极低码课程【redis windows下服务注册密码修改】
  • 多ip访问多网站
  • Pytest参数详解 — 基于命令行模式!