使用swiper实现轮播图
上代码前先记得导包:
https://www.cnblogs.com/zeng1997/p/11607991.html
这里面有教程
话不多说直接上代码:
<%-- Created by IntelliJ IDEA. User: admin Date: 2019/10/8 Time: 21:07 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html lang="en"> <head> <meta charset="utf-8"> <title>Swiper demo</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"> <!-- Link Swiper's CSS --> <link rel="stylesheet" href="<%=request.getContextPath()%>/swiper/swiper.min.css"> <!-- Demo styles --> <style> html, body { position: relative; height: 100%; } body { background: #eee; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 14px; color:#000; margin: 0; padding: 0; } .swiper-container { width: 100%; height: 100%; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; /* Center slide text vertically */ display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; -webkit-justify-content: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; -webkit-align-items: center; align-items: center; } </style> </head> <body> <!-- Swiper --> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide">Slide 1</div> <div class="swiper-slide">Slide 2</div> <div class="swiper-slide">Slide 3</div> <div class="swiper-slide">Slide 4</div> <div class="swiper-slide">Slide 5</div> <div class="swiper-slide">Slide 6</div> <div class="swiper-slide">Slide 7</div> <div class="swiper-slide">Slide 8</div> <div class="swiper-slide">Slide 9</div> <div class="swiper-slide">Slide 10</div> </div> <!-- Add Pagination --> <div class="swiper-pagination"></div> </div> <!-- Swiper JS --> <script src="<%=request.getContextPath()%>/swiper/swiper.min.js"></script> <!-- Initialize Swiper --> <script> var swiper = new Swiper('.swiper-container', { pagination: { el: '.swiper-pagination', dynamicBullets: true, }, }); </script> </body> </html>
<%-- Created by IntelliJ IDEA. User: admin Date: 2019/10/8 Time: 20:37 To change this template use File | Settings | File Templates. --%> <%-- Created by IntelliJ IDEA. User: zengt Date: 2019-09-29 Time: 11:19 To change this template use File | Settings | File Templates. --%> <%@ page contentType="text/html;charset=UTF-8" language="java" %> <html lang="en"> <head> <meta charset="utf-8"> <title>Swiper demo</title> <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1"> <!-- css路径 --> <%-- <link rel="stylesheet" href="<%=request.getContextPath()%>/swiper/swiper.min.css">--%> <link rel="stylesheet" href="swiper/swiper.min.css"> <!-- Demo styles --> <style> html, body { position: relative; height: 100%; } body { background: #eee; font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 14px; color:#000; margin: 0; padding: 0; } .swiper-container { width: 100%; height: 100%; } .swiper-slide { text-align: center; font-size: 18px; background: #fff; /* Center slide text vertically */ display: -webkit-box; display: -ms-flexbox; display: -webkit-flex; display: flex; -webkit-box-pack: center; -ms-flex-pack: center; -webkit-justify-content: center; justify-content: center; -webkit-box-align: center; -ms-flex-align: center; -webkit-align-items: center; align-items: center; } </style> </head> <body> <!-- Swiper --> <div class="swiper-container"> <div class="swiper-wrapper"> <div class="swiper-slide"> <img src="<%=request.getContextPath()%>/Img/nature-1.jpg"/> </div> <div class="swiper-slide"> <img src="<%=request.getContextPath()%>/Img/nature-2.jpg"/> </div> <div class="swiper-slide"> <img src="<%=request.getContextPath()%>/Img/nature-3.jpg"/> </div> <div class="swiper-slide"> <img src="<%=request.getContextPath()%>/Img/nature-4.jpg"/> </div> </div> <!-- Add Arrows --> <div class="swiper-button-next"></div> <div class="swiper-button-prev"></div> </div> <!-- js路径 --> <script src="swiper/swiper.min.js"></script> <%--<script src="<%=request.getContextPath()%>/swiper/swiper.min.js"></script>--%> <!-- Initialize Swiper --> <%--<script>--%> <%-- var swiper = new Swiper('.swiper-container', {--%> <%-- navigation: {--%> <%-- nextEl: '.swiper-button-next',--%> <%-- prevEl: '.swiper-button-prev',--%> <%-- },--%> <%-- });--%> <%--</script>--%> <script> var swiper = new Swiper('.swiper-container', { pagination: { el: '.swiper-pagination', dynamicBullets: true, }, }); </script> </body> </html>
图片未显示出来的问题还未解决???
本文作者:AxeBurner
本文链接:https://www.cnblogs.com/bichen-01/p/11638164.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix