1.自动轮播+经过圆点滚动+鼠标停留在圆点上 时候暂停+离开圆点自动轮播:
焦点图*{margin:0; padding:0; list-style:none;} .clear-fix{*zoom:1;} .clear-fix:after{ content:"\0020"; clear:both; height:0; display:block;} h1{ text-align:center;} .slider{width:980px; height:365px; margin:0 auto; position:relative;} .slider .img_box{width:980px; height:365px; overflow:hidden;} .slider ul{width:100000px;} .slider li{ width:980px; height:365px; float:left; background:#ccc; text-align:center; font-size:larger; line-height:365px;} .slider .num_box{ position:absolute; bottom:10px; right:10px;} .slider .num_box a{ width:10px; height:10px; background:#fff; border-radius:5px; display:inline-block;} .slider .num_box a.c{ background:#C00;}
鼠标经过圆点切换
//鼠标经过圆点的滚动: var n=0; function slider(n){ $("ul").animate({marginLeft:-n*980},1000); $(".num_box a").removeClass("c").eq(n).addClass("c"); } t=setInterval(function(){ n++; n=n>=$(".num_box a").length?0:n; slider(n); },3000) slider(n); $(".num_box a").hover(function(){ clearInterval(t); slider($(this).index()); },function(){ t=setInterval(function(){ n=$(".num_box a.c").index()+1; n=n>=$(".num_box a").length?0:n; slider(n); },3000) }) 焦点图1*{margin:0; padding:0; list-style:none;} .clear-fix{*zoom:1;} .clear-fix:after{ content:"\0020"; clear:both; height:0; display:block;} h1{ text-align:center;} .slider{width:980px; height:365px; margin:0 auto; position:relative;} .slider .img_box{width:980px; height:365px; overflow:hidden;} .slider ul{width:100000px;} .slider li{ width:980px; height:365px; float:left; background:#ccc; text-align:center; font-size:larger; line-height:365px;} .slider .num_box{ position:absolute; bottom:10px; right:10px;} .slider .num_box a{ width:10px; height:10px; background:#fff; border-radius:5px; display:inline-block;} .slider .num_box a.c{ background:#C00;}
鼠标点击圆点切换
var n=0; function slider(n){ $("ul").animate({marginLeft:-n*980},500); $(".num_box a").removeClass("c").eq(n).addClass("c"); } t=setInterval(function(){ n++; n=n>=$(".num_box a").length?0:n; slider(n); },3000) slider(n); $(".num_box a").click(function(){ clearInterval(t); slider($(this).index()); $(".num_box a").mouseout(function(){ clearInterval(t); t=setInterval(function(){ n=$(".num_box a.c").index()+1; n=n>=$(".num_box a").length?0:n; slider(n) },3000); }) }) 焦点图2*{margin:0; padding:0; list-style:none;} .clear-fix{*zoom:1;} .clear-fix:after{ content:"\0020"; clear:both; height:0; display:block;} h1{ text-align:center;} .top{ width:980px; margin:0 auto; position:relative;} .top input{ width:100px; position:absolute; top:10px;} .top .prev{ left:0;} .top .next{ position:absolute; right:0;} .slider{width:980px; height:365px; margin:0 auto; position:relative;} .slider .img_box{width:980px; height:365px; overflow:hidden;} .slider ul{width:100000px;} .slider li{ width:980px; height:365px; float:left; background:#ccc; text-align:center; font-size:larger; line-height:365px;} .slider .num_box{ position:absolute; bottom:10px; right:10px;} .slider .num_box a{ width:10px; height:10px; background:#fff; border-radius:5px; display:inline-block;} .slider .num_box a.c{ background:#C00;}
鼠标点击按钮切换
var n=0; function slider(index){ $("ul").stop().animate({marginLeft:-index*980},1000); $(".num_box a").removeClass("c").eq(index).addClass("c"); } //自动播放: t=setInterval(function(){ n++; n=n>=$(".num_box a").length?0:n; slider(n); },3000); //上一张: $(".prev").click(function(){ clearInterval(t); var index=$(".num_box a.c").index()-1; index=index<0?$(".num_box a").length-1:index; slider(index); }) //下一张: $(".next").click(function(){ clearInterval(t); var index=$(".num_box a.c").index()+1; index=index>=$(".num_box a").length?0:index; slider(index); }) //点击圆点向右滚动: $(".num_box a").click(function(){ clearInterval(t); var index=$(this).index(); slider(index); }) //鼠标移出按钮和圆点: $(".num_box a,.next,.prev").mouseout(function(){ clearInterval(t); t=setInterval(function(){ m=$(".num_box a.c").index()+1; m=m>=$(".num_box a").length?0:m; slider(m); },3000); })