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

35.图片幻灯片

图片幻灯片

html部分

<div class="carousel"><div class="image-container"><img src="./static/20180529205331_yhGyf.jpeg" alt="" srcset=""><img src="./static/20190214214253_hsjqw.webp" alt="" srcset=""><img src="./static/20190908084721_rjhtr.png" alt="" srcset=""><img src="./static/20200205192210_tKHiT.jpeg" alt="" srcset=""></div><div class="button-container"><div class="pre">pre</div><div class="next">next</div></div>
</div>

css部分

* {margin: 0;padding: 0;
}body {display: flex;justify-content: center;align-items: center;overflow: hidden;height: 100vh;
}img {flex-shrink: 0;width: 100% !important;height: 100% !important; object-fit: cover;transition: all .7s;
}.carousel {box-shadow: 0 10px 10px -5px rgba(0, 0, 0, 0.4);height: 530px;width: 500px;overflow: hidden;
}.image-container {width: 500px;height: 500px;display: flex;
}   
.button-container{display: flex;height: 30px;color: #fff;line-height: 1.8;cursor: pointer;
}
.button-container div:first-child:active{transform: scaleY(0.98) ;
}
.button-container div:last-child:active{transform: scaleY(0.98);
}
.button-container div:first-child{flex: 1;text-align: center;margin-right: 5px;background: rebeccapurple;
}
.button-container div:last-child{flex: 1;text-align: center;background: rebeccapurple;
}

js部分

// 获取dom
const pre = document.querySelector(".pre");
const next = document.querySelector(".next");
const img_box = document.querySelector(".image-container")
const imgs = document.querySelectorAll("img")// 初始活动元素
let active_index = 0// 下移
next.addEventListener("click", function (e) {active_index++if (active_index > imgs.length - 1) {active_index = 0;}change_img()
})
// 上移
pre.addEventListener("click", function (e) {active_index--if (active_index < 0) {active_index = imgs.length - 1;}change_img()
})// 所以元素前进或者后退
function change_img() {imgs.forEach((item) => {item.style.transform = `translate(${-active_index * 500}px)`})
}

效果

在这里插入图片描述

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

相关文章:

  • CentOS7系统Nvidia Docker容器基于TensorFlow2.12测试GPU
  • Go 下载安装教程
  • InnoDB数据存储结构
  • 基于ts的浏览器缓存工具封装(含源码)
  • GIT涵盖工作中用的相关指令
  • 【如何训练一个中英翻译模型】LSTM机器翻译seq2seq字符编码(一)
  • [JAVAee]文件操作-IO
  • 【数据集】3小时尺度降水数据集-MSWEPV2
  • Springboot之把外部依赖包纳入Spring容器管理的两种方式
  • 更安全,更省心丨DolphinDB 数据库权限管理系统使用指南
  • WPS本地镜像化在线文档操作以及样例
  • STM32 Flash学习(一)
  • Spring中IOC容器常用的接口和具体的实现类
  • 【MySQL】索引特性
  • 【深度学习笔记】动量梯度下降法
  • 《TCP IP网络编程》第十二章
  • 基于CNN卷积神经网络的调制信号识别算法matlab仿真
  • 正则,JS:this,同步异步,原型链笔记整理
  • 【NOIP】小鱼的数字游戏题解
  • 算法的时间复杂度、空间复杂度如何比较?
  • We are the Lights 2023牛客暑期多校训练营4-L
  • ant-design-vue中table组件使用customRender渲染v-html
  • 若依框架实现后端防止用户重复点击
  • PCA对手写数字数据集的降维
  • Python入门【变量的作用域(全局变量和局部变量)、参数的传递、浅拷贝和深拷贝、参数的几种类型 】(十一)
  • 下级平台级联安防视频汇聚融合EasyCVR平台,层级显示不正确是什么原因?
  • vue : 无法加载文件 C:\Users\jianfei\AppData\Roaming\npm\vue.ps1,因为在此系统上禁止运行脚本。...
  • godot引擎c++源码深度解析系列二
  • 专才or 通才
  • 【小白必看】Python爬虫实战之批量下载女神图片并保存到本地