首先引入css文件和html结构html结构<div class='poster-main carousel' data-setting='{}'>
<div class='poster-btn poster-prev-btn'></div> <ul class='poster-list'> <li class="list-item"> <a href="#"><img src="./image/01.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/02.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/03.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/04.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/05.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/06.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/07.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/08.jpg" alt=""></a> </li> <li class="list-item"> <a href="#"><img src="./image/09.jpg" alt=""></a> </li> </ul> <div class='poster-btn poster-next-btn'></div> </div>
3.配置参数是通过属性值读取的,在data-setting={}配置相关参数
{ "width": 1000, //幻灯片的宽度 "height": 270, //幻灯片的高度 "posterWidth": 640, //第一帧的高度 "posterHeight": 270, //第一帧的宽度 "verticalAlign": 'middle', "autoPlay": true, "speed": 500, "delay": 500, "scale": 0.9 //记录显示比例 },
须严格按照json格式配置。在文件中引入jquery插件和carouse.js,执行如下脚本: