作为新手,自己编写的一个轮播图,希望可以帮助到一些人

作为新手,自己编写的一个轮播图,希望可以帮助到一些人
这里写图片描述
以上是HTML代码很简单,应该可以一眼看懂
*{
margin: 0;
padding: 0;
}
ul{
list-style:none ;
}
/* banner star*/
.banner{
height: 200px;
width: 800px;
/background: blue;/
margin: 50px auto;
position: relative;
}
.banner .pic img{
height: 200px;
width: 800px;
position: absolute;
display: none;
}
.banner .pic img.show{
display: block;
}
.banner .btn{
font-size: 50px;
height: 200px;
line-height: 200px;
color: white;
font-family: 黑体;
font-weight:bold ;
display: none;
}
.banner:hover .btn{
display: block;
}
.banner .btn .left{
position: absolute;
left: 15px;
}
.banner .btn .right{
position: absolute;
right: 15px;
}
.banner .tab{
/*border: 1px solid red;
height: 17px;
width: 118px;*/
position: absolute;
bottom: 15px;
left: 50%;
margin-left:-59px ;
}
.banner .tab li{
height: 15px;
width: 15px;
border: 1px solid white;
border-radius:50% ;
float: left;
margin-left: 10px;
}
.banner .tab li:hover{
background: white;
}
.banner .tab .active{
background: white;
}
这是css的代码,比较繁琐
(function () {  
    //获取操作对象  
    var
(function () {      //获取操作对象      var
pic= (.banner.picimg);//var ( “ . b a n n e r . p i c i m g ” ) ; / / 图 片 对 象 v a r btn= (.banner.btnli);var ( “ . b a n n e r . b t n l i ” ) ; v a r tab= (.banner.tabli);varlen= ( “ . b a n n e r . t a b l i ” ) ; v a r l e n = pic.length;
pic.eq(0).addClass(show); p i c . e q ( 0 ) . a d d C l a s s ( “ s h o w ” ) ; tab.eq(0).addClass(“active”);
var n_index=0;
tab.click(function()//console.log($(this).index());varnum=$(this).index();if(num!=nindex)change(num);); t a b . c l i c k ( f u n c t i o n ( ) / / c o n s o l e . l o g ( $ ( t h i s ) . i n d e x ( ) ) ; v a r n u m = $ ( t h i s ) . i n d e x ( ) ; i f ( n u m ! = n i n d e x ) c h a n g e ( n u m ) ; ) ; btn.click(function () {
var num=n_index;
console.log( (this).index());if( ( t h i s ) . i n d e x ( ) ) ; i f ( (this).index()){//1
num++;
console.log(num);
num%=len;//取余
}else {//0
num–;
console.log(num);
num%=len;
}
change(num);
});
function change(num) {
pic.eq(nindex).fadeOut(2000); p i c . e q ( n i n d e x ) . f a d e O u t ( 2000 ) ; tab.eq(n_index).removeClass(“active”);
n_index=num;
pic.eq(num).fadeIn(2000); p i c . e q ( n u m ) . f a d e I n ( 2000 ) ; tab.eq(num).addClass(“active”);
}
setInterval(f,3000);
function f() {
var num=n_index;
num++;
num%=len;
change(num)
}
});
jq的代码。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值