美文网首页
jQuery轮播图实现

jQuery轮播图实现

作者: raining_804f | 来源:发表于2018-02-22 19:26 被阅读0次

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);

})

})

相关文章

  • 项目-轮播图

    整个轮播图分为三部分:轮播指标、轮播项目及轮播导航。用boostrap实现轮播图要比用js、jQuery方便的多,...

  • jquery代码实现爱奇艺轮播图效果

    爱奇艺轮播图效果的jquery代码实现。 html部分: css部分: jquery部分:

  • 用js原生实现轮播图

    用jquery实现轮播图非常简单的啦!有没有想过用原生js实现轮播图呢???今天琢磨了一下,摸索出来一个,就和大家...

  • jQuery轮播图实现

    html: 备注:图片width:730px height:454px css: @charset "utf-8"...

  • jQuery实现轮播图

    题目1: 轮播的实现原理是怎样的?如果让你来实现,你会抽象出哪些函数(or接口)供使用?(比如 play()) 轮...

  • 2018-07-30

    Jquery和纯JS实现轮播图(一)--左右切换式 一、页面结构 对于左右切换式的轮播图的结构主要分为以下几个部分...

  • web常用库

    js retina.js 实现retina屏幕图片自动替换 slick.js jQuery插件,实现各种轮播图 w...

  • Vue轮播图的实现以及其与jQuery轮播图的简单对比

    最近在学习Vue,然后做了一个轮播图,然后想起之前用jQuery做的轮播图,就打算进行一个对比。 jQuery轮播...

  • jQuery相关插件

    jQuery全屏滚动插件fullPage.js jquery轮播图插件unslider

  • Jquery和纯JS实现轮播图--淡入淡出切换式

    今天分享一下淡入淡出式的轮播图,同样也是用纯js和Jquery两种方法来实现:JQUERY实现HTML结构: CS...

网友评论

      本文标题:jQuery轮播图实现

      本文链接:https://www.haomeiwen.com/subject/xnvztftx.html