jquery滚动轮播

本文介绍了一个使用JavaScript和CSS实现的轮播图自动切换效果。通过设置定时器自动改变图片显示,并利用鼠标悬停事件暂停轮播,点击按钮进行手动切换。同时实现了指示点跟随当前显示的图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<script type="text/javascript">
$(function(){
var num=0;
var timer =setInterval(add,1000)
//定时器函数
function add(){
num++;

if(num==6){
$('.dian ul li').eq(0).addClass('active').siblings().removeClass('active')
}
if(num==7){
$('.list').css({'left':'0px'});
num=1;
}
$('.list').stop().animate({
'left':-1024*num+'px'
})
$('.dian ul li').eq(num).addClass('active').siblings().removeClass('active')
}
//鼠标滑过大块的时候
$('#wrap').hover(function(){
//清除定时器
clearInterval(timer)
},function(){
//启动定时器
timer =setInterval(add,1000)
})
//点击左边的时候
$('#left').click(function(){
num--;
if(num==-1){
$('.dian ul li').eq(5).addClass('active').siblings().removeClass('active')
}
if(num==-1){
num= 5;
$('.list').css({'left':-6144+'px'});
}
$('.list').stop().animate({
'left':-1024*num+'px'
})
$('.dian ul li').eq(num).addClass('active').siblings().removeClass('active')
})
//点击右边的时候
$('#right').click(function(){
num++;
if(num==6){
$('.dian ul li').eq(0).addClass('active').siblings().removeClass('active')
}
if(num==7){
num= 1
$('.list').css({'left':'0px'});
}
$('.list').stop().animate({
'left':-1024*num+'px'
})
$('.dian ul li').eq(num).addClass('active').siblings().removeClass('active');

})
//下面小点
$('.dian ul li').click(function(){
num==$(this).index()
$('.list').stop().animate({
'left':-1024*num+'px'
})
$(this).addClass('active').siblings().removeClass('active')

})

})

</script>

/////html////////////////

<div id="wrap">
<ul class="list">
<li><a href=""><img src="img/banner1.jpg"/></a></li>
<li><a href=""><img src="img/banner2.jpg"/></a></li>
<li><a href=""><img src="img/banner3.jpg"/></a></li>
<li><a href=""><img src="img/banner4.jpg"/></a></li>
<li><a href=""><img src="img/banner5.jpg"/></a></li>
<li><a href=""><img src="img/banner6.jpg"/></a></li>
<li><a href=""><img src="img/banner1.jpg"/></a></li>
</ul>
<a href="#" class="left att" id="left"><</a>
<a href="#" class="right att" id="right">></a>
<div class="dian">
<ul>
<li class="active"></li>
<li></li>
<li></li>
<li></li>
<li></li>
<li></li>
</ul>
</div>
</div>

/////////////////////////////css/////////////////////////////

<style type="text/css">
*{
margin: 0;
padding: 0;
}
ol,ul,li{
list-style: none;
}
#wrap{
width: 1024px;
height: 320px;
margin: 0 auto;
position: relative;
overflow: hidden;
}
#wrap .list {
width: 7168px;
height: 320px;
position: absolute;
top: 0px;
left: 0px;
}
#wrap .list li{
float: left;
}
.att{
position: absolute;
top: 40%;
width: 30px;
height: 60px;
background: black;
opacity: 0.5;
line-height: 60px;
text-align: center;
font-size: 30px;
color: white;
text-decoration: none;
}
.left{
left: 0px;
}
.right{
right: 0px;
}
.dian{
width: 100px;
height: 30px;
position: absolute;
bottom: 0px;
right: 100px;
}
.dian>ul>li{
width: 10px;
height: 10px;
background: #343535;
border-radius: 50%;
float: left;
margin-left: 5px;
}
.dian>ul .active{
background: red;
}
</style>

/* * 基于双向链表实现双端队列结构 */ package dsa; public class Deque_DLNode implements Deque { protected DLNode header;//指向头节点(哨兵) protected DLNode trailer;//指向尾节点(哨兵) protected int size;//队列中元素的数目 //构造函数 public Deque_DLNode() { header = new DLNode(); trailer = new DLNode(); header.setNext(trailer); trailer.setPrev(header); size = 0; } //返回队列中元素数目 public int getSize() { return size; } //判断队列是否为空 public boolean isEmpty() { return (0 == size) ? true : false; } //取首元素(但不删除) public Object first() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); return header.getNext().getElem(); } //取末元素(但不删除) public Object last() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); return trailer.getPrev().getElem(); } //在队列前端插入新节点 public void insertFirst(Object obj) { DLNode second = header.getNext(); DLNode first = new DLNode(obj, header, second); second.setPrev(first); header.setNext(first); size++; } //在队列后端插入新节点 public void insertLast(Object obj) { DLNode second = trailer.getPrev(); DLNode first = new DLNode(obj, second, trailer); second.setNext(first); trailer.setPrev(first); size++; } //删除首节点 public Object removeFirst() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); DLNode first = header.getNext(); DLNode second = first.getNext(); Object obj = first.getElem(); header.setNext(second); second.setPrev(header); size--; return(obj); } //删除末节点 public Object removeLast() throws ExceptionQueueEmpty { if (isEmpty()) throw new ExceptionQueueEmpty("意外:双端队列为空"); DLNode first = trailer.getPrev(); DLNode second = first.getPrev(); Object obj = first.getElem(); trailer.setPrev(second); second.setNext(trailer); size--; return(obj); } //遍历 public void Traversal() { DLNode p = header.getNext(); while (p != trailer) { System.out.print(p.getElem()+" "); p = p.getNex
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值