jquery实现垂直无限轮播的方法分析

2020-05-19 07:28:48易采站长站整理

本文实例讲述了jquery实现垂直无限轮播的方法。分享给大家供大家参考,具体如下:

javascript垂直轮播,依赖于jquery实现的,并且首尾无缝衔接。原理很简单,就不讲述了,直接贴源码。

1.HTML节点


<div class="banner_group">
<ul id="banner">
<!-- 缓存末项,实现滑动到最开始后,无限轮播 -->
<li style="background-color: chartreuse">第四页</li>
<li style="background-color: #f6894d">第一页</li>
<li style="background-color: royalblue">第二页</li>
<li style="background-color: red">第三页</li>
<li style="background-color: chartreuse">第四页</li>
<!-- 缓存首项,实现滑动到最后过后,无限轮播 -->
<li style="background-color: #f6894d">第一页</li>
</ul>
<div class="scrollPageBtn">
<div style="width: 100%;height: 100%;position: relative;">
<label id="last" style="width:100%;position: absolute;top: 0;text-align: center">↑</label>
<label id="next" style="width:100%;position: absolute;bottom: 0;text-align: center">↓</label>
</div>
</div>
</div>

2.CSS样式


<style>
body{
margin:0;
padding: 0;
}
.banner_group{
width: 300px;
height: 500px;
overflow: hidden;
position: relative;
}
.scrollPageBtn{
width: 30px;
height: 100%;
position: absolute;
top: 0;
left: 40%;
background-color: #b2b2b2;
opacity: 0.2;
}
ul{
list-style: none;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
position: relative;
}
ul li{
width: 100%;
height: 100%;
color: white;
font-size: 25px;
}
</style>

3.JQuery准备


<!-- 引入jquery -->
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

4.JavaScript代码


<script>
var index = 0; // 保存当前所在项
/* 是否允许点击滑动动画,如果正在执行动画的过程中,
则禁止点击,如果动画完成后,则允许点击,
避免由于连点,出现画面不正常问题. */
var allowClick = true; //
// 页面加载完成后调用
$(function(){
index = 1; // 初始显示第2项