1、百度圖片輪播圖unslider,第一個就會出現jquery unslider輪播圖,點擊進去,下載網站提供的文件,解壓,內部有我們需要使用的各種js,圖片等。
2、在自己的eclipse或者intellij idea中搭建一個可以正常運行的web工程
3、在WEB-INF下創建一個jsp文件夾,jsp文件夾下創建一個lunbo.jsp,顏色標記的代碼是需要注意的!在WebRoot下創建js和img文件夾,存放js和所需要的圖片。
頁面的代碼:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>測試</title>
</head>
<!-- 首先引入jQuery和unslider -->
<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<script src="${pageContext.request.contextPath}/js/unslider.min.js"></script>
<!-- 最后用js控制 -->
<script>
$(document).ready(function(e) {
var unslider04 = $('#b04').unslider({
dots: true
}),
data04 = unslider04.data('unslider');
$('.unslider-arrow04').click(function() {
var fn = this.className.split(' ')[1];
data04[fn]();
});
});
</script>
<style>
ul, ol { padding: 0;}
.banner { position: relative; overflow: auto; text-align: center;}
.banner li { list-style: none; }
.banner ul li { float: left; }
#b04 { width: 640px;}
#b04 .dots { position: absolute; left: 0; right: 0; bottom: 20px;}
#b04 .dots li
{
display: inline-block;
width: 10px;
height: 10px;
margin: 0 4px;
text-indent: -999em;
border: 2px solid #fff;
border-radius: 6px;
cursor: pointer;
opacity: .4;
-webkit-transition: background .5s, opacity .5s;
-moz-transition: background .5s, opacity .5s;
transition: background .5s, opacity .5s;
}
#b04 .dots li.active
{
background: #fff;
opacity: 1;
}
#b04 .arrow { position: absolute; top: 200px;}
#b04 #al { left: 15px;}
#b04 #ar { right: 15px;}
</style>
<body>
<!-- 把要輪播的地方寫上來 -->
<div class="banner" id="b04">
<ul>
<li><img src="${pageContext.request.contextPath}/img/01.jpg" alt="" width="640" height="480" ></li>
<li><img src="${pageContext.request.contextPath}/img/02.jpg" alt="" width="640" height="480" ></li>
<li><img src="${pageContext.request.contextPath}/img/03.jpg" alt="" width="640" height="480" ></li>
<li><img src="${pageContext.request.contextPath}/img/04.jpg" alt="" width="640" height="480" ></li>
<li><img src="${pageContext.request.contextPath}/img/05.jpg" alt="" width="640" height="480" ></li>
</ul>
<a href="javascript:void(0);" class="unslider-arrow04 prev"><img class="arrow" id="al" src="${pageContext.request.contextPath}/img/arrowl.png" alt="prev" width="20" height="35"></a>
<a href="javascript:void(0);" class="unslider-arrow04 next"><img class="arrow" id="ar" src="${pageContext.request.contextPath}/img/arrowr.png" alt="next" width="20" height="37"></a>
</div>
</body>
</html>
4、寫一個頁面跳轉,跳轉到我們頁面的輪播界面。
@RequestMapping("/lunbo")
public String lunBo(){
return "lunbo";
}
5、如果頁面沒有出先圖片,注意靜態資源不可以攔截,需要放行!
<!--使用注解的方法配置處理器 -->
<context:component-scan base-package="cn.itcast.ssm.controller"></context:component-scan>
<!--注解映射器 適配器配置 使用mvc標簽 -->
<mvc:annotation-driven/>
<mvc:resources mapping="/resources/**" location="/resources/"/>
<mvc:resources mapping="/css/**" location="/css/"/>
<mvc:resources mapping="/img/**" location="/img/"/>
<mvc:resources mapping="/js/**" location="/js/"/>
<!--配置視圖解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
6、啟動項目一般就可以實現功能了!