网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

jquery写轮播图,jquery怎么写轮播图

如何用jquery做轮播图

有很多可供选择的JQ插件,比如

创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于网站制作、成都网站制作、黄石港网络推广、微信小程序、黄石港网络营销、黄石港企业策划、黄石港品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联公司为所有大学生创业者提供黄石港建站搭建服务,24小时服务热线:18980820575,官方网址:www.cdcxhl.com

slider、bxslider、swipper等等,这些都是比较方便且功能强大的,例子可以参考官方的Demo

左右按钮控制轮播图切换,用jquery怎么写,不用框架,代码如下

!doctype html

html lang="en"

head

meta charset="UTF-8"

titleDocument/title

style

#box {

width: 796px;

margin: 50px auto;

position: relative;

height: 296px;

}

#img-box img {

position: absolute;

width: 796px;

height: 305px;

}

#uls {

position: absolute;

width: 100%;

text-align: center;

bottom: 0px;

list-style: none;

margin: 0;

padding: 0;

}

#uls li {

width: 30px;

height: 30px;

line-height: 30px;

background: white;

border-radius: 10px;

display: inline-block;

}

#uls li:first-child {

background: red;

}

button {

position: absolute;

top: 50%;

display: none;

}

button#prev {

left: 10px;

}

button#next {

right: 10px;

}

/style

/head

body

div id="box"

div id="img-box"

img src="" alt=""

img src="" alt=""

img src="" alt=""

img src="" alt=""

img src="" alt=""

/div

ul id="uls"

li1/li

li2/li

li3/li

li4/li

li5/li

/ul

button id="prev"/button

button id="next"/button

/div

script src=""/script

script

var time, len;

var index = 0

len = $('#uls li').length;

time = setInterval(slide, 1000);

$('#box').hover(function() {

clearInterval(time);

$('#prev,#next').css('display', 'block');

}, function() {

time = setInterval(slide, 1000);

$('#prev,#next').css('display', 'none');

});

$('#prev').click(function() {

clearInterval(time);

var len = $('#uls li').length - 1;

var imgshowindex = $("#img-box img:visible").index();

if (imgshowindex = 0) {

index = len;

} else {

index = --imgshowindex;

}

showindeximg(index);

});

$('#next').click(function() {

clearInterval(time);

var imgshowindex = $("#img-box img:visible").index();

index = ++imgshowindex;

if (index == len) index = 0;

showindeximg(index);

});

function slide() {

index++;

if (index == len) index = 0;

$('#uls li').css('background', 'white').eq(index).css('background', 'red');

$('#img-box img').fadeOut();

$('#img-box img').eq(index).fadeIn();

}

function showindeximg(index) {

$("#img-box img").hide().eq(index).show();

$("#uls li").css("background", "white").eq(index).css("background", "red");

}

/script

/body

/html

具体实现,你可以复制下来运行下。

用jquery实现图片轮播怎么写呢求指教

*{  

margin: 0;  

padding: 0;  

}  

ul{  

list-style:none;  

}  

.slideShow{  

width: 620px;  

height: 700px;     /*其实就是图片的高度*/  

border: 1px #eeeeee solid;  

margin: 100px auto;  

position: relative;  

overflow: hidden;    /*此处需要将溢出框架的图片部分隐藏*/  

}  

.slideShow ul{  

width: 2500px;  

position: relative;     /*此处需注意relative : 对象不可层叠,但将依据left,right,top,bottom等属性在正常文档流中偏移位置,如果没有这个属性,图片将不可左右移动*/  

}  

.slideShow ul li{  

float: left;     /*让四张图片左浮动,形成并排的横着布局,方便点击按钮时的左移动*/  

width: 620px;  

}  

.slideShow .showNav{     /*用绝对定位给数字按钮进行布局*/  

position: absolute;  

right: 10px;  

bottom: 5px;  

text-align:center;  

font-size: 12px;      

line-height: 20px;  

}  

.slideShow .showNav span{  

cursor: pointer;  

display: block;  

float: left;  

width: 20px;  

height: 20px;  

background: #ff5a28;  

margin-left: 2px;  

color: #fff;  

}  

.slideShow .showNav .active{  

background: #b63e1a;  

}  

js代码规范:

script src="../../../jQuery/js/jquery-2.1.4.js"/script script type="text/javascript"  

$(document).ready(function(){      

var slideShow=$(".slideShow"),                                                                    //获取最外层框架的名称     

ul=slideShow.find("ul"),               

showNumber=slideShow.find(".showNav span"),                                              //获取按钮          

oneWidth=slideShow.find("ul li").eq(0).width();                                        //获取每个图片的宽度          

var timer=null;                                                                                     //定时器返回值,主要用于关闭定时器          

var iNow=0;                                                                                         //iNow为正在展示的图片索引值,当用户打开网页时首先显示第一张图,即索引值为0                  

showNumber.on("click",function(){                                                      //为每个按钮绑定一个点击事件                   

$(this).addClass("active").siblings().removeClass("active");                  //按钮点击时为这个按钮添加高亮状态,并且将其他按钮高亮状态去掉              

var index=$(this).index();                                                                //获取哪个按钮被点击,也就是找到被点击按钮的索引值              

iNow=index;              

ul.animate({    "left":-oneWidth*iNow,                               //注意此处用到left属性,所以ul的样式里面需要设置position: relative; 让ul左移N个图片大小的宽度,N根据被点击的按钮索引值iNOWx确定            

})        

});                 

function autoplay(){      

timer=setInterval(function(){                                              //打开定时器             

iNow++;                                                                         //让图片的索引值次序加1,这样就可以实现顺序轮播图片             

if(iNowshowNumber.length-1){                                      //当到达最后一张图的时候,让iNow赋值为第一张图的索引值,轮播效果跳转到第一张图重新开始                  

iNow=0; }              

showNumber.eq(iNow).trigger("click");                                  //模拟触发数字按钮的click          

},2000);                                                                      //2000为轮播的时间  

}     

autoplay();     

slideShow.hover( function(){clearInterval(timer);},autoplay);     另外注意setInterval的用法比较关键。  

})  

/script  

主体代码:

[html] view plain copy print?

body  

div class="slideShow"  

!--图片布局开始--  

ul  

lia href="#"img src="images/view/111.jpg"//a/li  

lia href="#"img  src="images/view/112.jpg" //a/li  

lia href="#"img src="images/view/113.jpg" //a/li  

lia href="#"img  src="images/view/114.jpg" //a/li  

/ul  

!--图片布局结束--  

!--按钮布局开始--  

div class="showNav"  

span class="active"1/span  

span2/span  

span3/span  

span4/span  

/div  

!--按钮布局结束--  

/div  

/body

jquery简单自动轮播图代码怎么写

html部分           this is the page一     this is the page二     this is the page三     this is the page四          css部分 *{     padding: 0;     margin: 0;     }     html,body{     height: 一00%;     }     #container {     width: 一00%;     height: 500px;     overflow: hidden;     }     .sections,.section {     height:一00%;     }     #container,.sections {     position: relative;     }     .section {     background-color: #000;     background-size: cover;     background-position: 50% 50%;     text-align: center;     color: white;     }     #section0 {     background-image: url('images/一.jpg');     }     #section一 {     background-image: url('images/二.jpg');     }     #section二 {     background-image: url('images/三.jpg');     }     #section三 {     background-image: url('images/四.jpg');     }   .pages li{list-style-type:none;width:一0px;height:一0px;border-radius:一0px;background-color:white}.pages li:hover{box-shadow:0 0 5px 二px white}.pages li.active{background-color:orange;box-shadow:0 0 5px 二px orange}.pages{position:absolute;z-index:999}.pages.horizontal{left:50%;transform:translateX(-50%);bottom:5px}.pages.horizontal li{display:inline-block;margin-right:一0px}.pages.horizontal li:last-child{margin-right:0}.pages.vertical{right:5px;top:50%;transform:translateY(-50%)}.pages.vertical li{margin-bottom:一0px}.pages.vertical li:last-child{margin-bottom:0} JS部分 jquery-一.一一.0.min.js" type="text/javascript" //引入pageSwitch.min.js 如

如何jQuery实现图片轮播的同时左右按钮可以实现切换?

建议,在当前轮播图的div添加类active,设置.active {display:block;},.ban{display:none;};这样可以通过添加或移除active就可以了;这样以下就比较方便很多,要不然又要做循环,麻烦(swiper插件做轮播效果不错)

$(".left").click(function(){

var $index = $(".ban").hasClass("active").index();//获取当前轮播图的下标

if($index === 0 ) {//当前为第一张轮播图

$(".ban").eq($(".ban").length-1).addClass("active)

.siblings(".ban").removeClass("active");

//这里写成你自动切换的代码,我这里只是一个无动态切换效果的方法

}else {

$(".ban").eq($index-1).addClass("active)

.siblings(".ban").removeClass("active");

})

$(".right").click(function(){

var $index = $(".ban").hasClass("active").index();//获取当前轮播图的下标

if($index === ($(".ban").length-1) ) {//当前为最后一张轮播图

$(".ban").eq($(".ban").length-1).addClass("active)

.siblings(".ban").removeClass("active");

//这里写成你自动切换的代码,我这里只是一个无动态切换效果的方法

}else {

$(".ban").eq($index+1).addClass("active)

.siblings(".ban").removeClass("active");

})

//大体思路是这样了,代码可能有个别字母写得不对,毕竟是手敲的,但是大概思路是这样了

jquery图片上下轮播的问题,怎么实现自动轮播?

1、html部分

body

div id="banner"    

div id="banner_bg"/div!--标题背景--

div id="banner_info"/div!--标题--

ul

li class="on"1/li

li2/li

li3/li

li4/li

/ul

div id="banner_list"

a href="#" target="_blank"img src="imgs/p1.jpg" title="橡树小屋的blog" alt="橡树小屋的blog"//a

a href="#" target="_blank"img src="imgs/p5.jpg" title="橡树小屋的blog" alt="橡树小屋的blog"//a

a href="#" target="_blank"img src="imgs/p3.jpg" title="橡树小屋的blog" alt="橡树小屋的blog"//a

a href="#" target="_blank"img src="imgs/p4.jpg" title="橡树小屋的blog" alt="橡树小屋的blog"//a

/div

/div

/body

2、css样式部分

style type="text/css"

#banner {position:relative; width:478px; height:286px; border:1px solid #666; overflow:hidden;}

#banner_list img {border:0px;}

#banner_bg {position:absolute; bottom:0;background-color:#000;height:30px;filter: Alpha(Opacity=30);opacity:0.3;z-index:1000;

cursor:pointer; width:478px;}

#banner_info{position:absolute; bottom:0; left:5px;height:22px;color:#fff;z-index:1001;cursor:pointer}

#banner_text {position:absolute;width:120px;z-index:1002; right:3px; bottom:3px;}

#banner ul {position:absolute;list-style-type:none;filter: Alpha(Opacity=80);opacity:0.8; border:1px solid #fff;z-index:1002;

margin:0; padding:0; bottom:3px; right:5px;}

#banner ul li { padding:0px 8px;float:left;display:block;color:#FFF;border:#e5eaff 1px solid;background:#6f4f67;cursor:pointer}

#banner ul li.on { background:#900}

#banner_list a{position:absolute;} !-- 让四张图片都可以重叠在一起--

/style

3、jQuery部分

script type="text/javascript"

var t = n =0, count;

$(document).ready(function(){    

count=$("#banner_list a").length;

$("#banner_list a:not(:first-child)").hide();

$("#banner_info").html($("#banner_list a:first-child").find("img").attr('alt'));

$("#banner_info").click(function(){window.open($("#banner_list a:first-child").attr('href'), "_blank")});

$("#banner li").click(function() {

var i = $(this).text() -1;//获取Li元素内的值,即1,2,3,4

n = i;

if (i = count) return;

$("#banner_info").html($("#banner_list a").eq(i).find("img").attr('alt'));

$("#banner_info").unbind().click(function(){window.open($("#banner_list a").eq(i).attr('href'), "_blank")})

$("#banner_list a").filter(":visible").fadeOut(500).parent().children().eq(i).fadeIn(1000);

document.getElementById("banner").style.background="";

$(this).toggleClass("on");

$(this).siblings().removeAttr("class");

});

t = setInterval("showAuto()", 4000);

$("#banner").hover(function(){clearInterval(t)}, function(){t = setInterval("showAuto()", 4000);});

})

function showAuto()

{

n = n =(count -1) ?0 : ++n;

$("#banner li").eq(n).trigger('click');

}

/script


分享名称:jquery写轮播图,jquery怎么写轮播图
网址分享:http://bjjierui.cn/article/dsdisie.html

其他资讯