jQuery轮播图实现

html:

备注:图片width:730px height:454px


css:

@charset "utf-8";

* {

margin: 0;

padding: 0;

}

ul {

list-style: none;

}

.container {

width: 730px;

height: 454px;

position: relative;

overflow: hidden;

margin: 50px auto;

}

.container .list {

width: 5110px;

height: 454px;

position: absolute;

top: 0;

left: 0;

}

.list li {

float: left;

width: 730px;

}

img {

border: none;

width: 100%;

}

.container .arrow {

width: 50px;

height: 60px;

text-align: center;

line-height: 60px;

display: none;

text-decoration: none;

position: absolute;

top: 197px;

z-index: 2;

color: #FFFFFF;

font-size: 30px;

border-radius: 10px;

background: rgba(50, 54, 57, .5);

}

.container:hover .arrow {

display: block;

}

.container .pre {

left: 10px;

}

.container .next {

right: 10px;

}

.container .dot {

position: absolute;

bottom: 20px;

right: 20px;

}

.dot span {

border-radius: 5px;

width: 25px;

text-align: center;

display: inline-block;

background:rgba(142, 227, 145,.6);

}

.dot .active{

color: #FFFFFF;

background: #b0d61f;

}

js:

$(function() {

var timer = null;

var index = 0;

//左右箭头点击事件

$('.next').click(nextRun);

$('.pre').click(preRun);

function nextRun() {

if(index < 5) {

index++;

$('.list').animate({

'left': index * -730

}, 1000);

} else {

index = 0;

$('.list').animate({

'left': 6 * -730

}, 1000, function() {

$('.list').css({

'left': 0

}, 1000);

})

}

dots();

}

function preRun() {

if(index > 0) {

index--;

$('.list').animate({

'left': index * -730

}, 1000);

} else {

index = 5;

$('.list').css({

'left': 6 * -730

}, 1000);

$('.list').animate({

'left': index * -730

}, 1000);

}

dots();

}

function dots() {

$('.dot span').eq(index).addClass('active').siblings().removeClass('active');

}

function autoPlay() {

timer = setInterval(nextRun, 2000);

}

autoPlay();

$('.container').hover(function() {

clearInterval(timer);

}, function() {

autoPlay();

})

$('.dot span').click(function() {

index = $(this).index();

dots();

$('.list').animate({

'left': index * -730

}, 1000);

})

})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 1. tab列表折叠效果 html: 能源系统事业部 岗位名称: 工作地点 岗位名...
    lilyping阅读 1,899评论 0 1
  • CSS 轮播 *{padding:0;margin:0;list-style:none;} .box{ margi...
    dovlie阅读 303评论 0 0
  • 进入前端将近一年了,js还是很弱,突发奇想写一个轮播图,就找到了这个博主的材料,和大家分享。 轮播图的原理: 一系...
    FRRRR阅读 3,684评论 0 11
  • 弗的研究由几个部分组成,主要反映在经济建模的理念,他建立了一批大型的经济模型类,这些模型类型对于中期政策的实施目的...
    鹏仔百分百阅读 185评论 0 0
  • 明发不寐,有怀二人。 ——李元吉的奶娘陈老夫人翘出兰花指,围着我们没完没了地哼唱着“宛彼鸣鸠,翰飞戾天。我心忧伤...
    梨涡小篆本尊阅读 429评论 0 3