[js简单的轮播图]

[知识点]

主要的知识点:点位,定时器,运动函数,jq,css

图片展示:

 

[css]

css完全可以按自己喜欢的方式来, 

.wrap {

                width: 650px;

                height: 365px;

                margin-top: 10px;

                margin-left: auto;

                margin-right: auto;

            }

            .slidepic {

                position: relative;

                height: 365px;

            }

            .hd {

                position: absolute;

                z-index: 10;

                width: 100%;

                height: 100%;

                display: none;

            }

            .hd a {

                position: absolute;

                left: -100px;

                top: 40%;

                width: 76px;

                height: 112px;

                background: url() 0 0 no-repeat;

            }

            .me{

                margin: 0;

                padding: 0;

                font-size: 12px;

                color: #666;

                text-align:center;

                padding-top:15px;

            }

            .slidepic>ul>li{

                display: list-item;

                text-align: -webkit-match-parent;

            }

            #myself {

                position: relative;

                width: 100%;

                height: 700px;

                overflow: hidden;

                background-color: #DEDEDE;

            }

            .slidepic ul {

                position: absolute;

                left: 0;

                top:0px;

                z-index: 1;

                list-style-type: none;

            }

            ul,menu,dir {

                display: block;

                list-style-type: disc;

                -webkit-margin-before: 1em;

                -webkit-margin-after: 1em;

                -webkit-margin-start: 0px;

                -webkit-margin-end: 0px;

                -webkit-padding-start: 40px;

            }

            .hd .next{

                right:0px;

                left:470px;

                background-image: url();

            }

            div {

                display: block;

            }

            body {

                overflow-x: hidden;

            }

            div#aboutme, div#case1 {

                width: 292px;

                height: 127px;

                margin: 20px auto;

                margin-bottom: 20px;

            }

            #myself p, #case p {

                width: 800px;

                margin: 0px auto;

                text-align: center;

                margin-top: 10px;

                color: #8C8C8C;

            }

            .slidepic li {

                position: absolute;

                width: 450px;

                height: 253px;

                left: 0px;

                top: 0;

                background-color: #6475ae;

                list-style-type: none;

            }

[html]

     
<div class="wrap">
               <div class="slidepic" id="slidepic">
                   <ul>
                       <li style="z-index: 2; width: 200px; height: 100px; left: -166px; top: 0px; opacity: 0;"     ><img src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/09/ChMkJ1bKzdKIJ8mGACiptxsKVJMAALJEgE9JDwAKKnP534.jpg" style="width: 100%; height: 100%;"    ></li>
                       <li style="z-index: 3; width: 200px; height: 100px;  left: -166px; top: 79px; opacity: 0.8;"  ><img src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/09/ChMkJ1bKzdKIJ8mGACiptxsKVJMAALJEgE9JDwAKKnP534.jpg"  style="width: 100%; height: 100%;" ></li>
                       <li style="z-index: 4;width: 200px; height: 100px;  left: 0px; top: 20px; opacity: 0;"       ><img src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/09/ChMkJ1bKzdKIJ8mGACiptxsKVJMAALJEgE9JDwAKKnP534.jpg"  style="width: 100%; height: 100%;"      ></li>
                       <li style="z-index: 3; width: 200px; height: 100px;  left: 390px; top: 79px; opacity: 0.8;"   ><img src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/09/ChMkJ1bKzdKIJ8mGACiptxsKVJMAALJEgE9JDwAKKnP534.jpg"  style="width: 100%; height: 100%;"  ></li>
                       <li style="z-index: 2; width: 200px; height: 100px;  left: 390px; top: 0px; opacity: 0;"      ><img src="https://desk-fd.zol-img.com.cn/t_s960x600c5/g5/M00/02/09/ChMkJ1bKzdKIJ8mGACiptxsKVJMAALJEgE9JDwAKKnP534.jpg"  style="width: 100%; height: 100%;"     ></li>
                   </ul>
                   <div class="hd" style="display: none;">
                       <a href="javascript:;" class="prev"></a>
                       <a href="javascript:;" class="next"></a>
                   </div>
               </div>
           </div>
       </div>  
  <script src="http://code.jquery.com/jquery-latest.js"></script>

[js]

 $(function(){
           var $slidepic = $('#slidepic');
           var aLi = $slidepic.find('li');
           var timer = null;
           var off = true;
           //定义li定位数据
           var pos = [
               {
                   width:260,
                   height:180,
                   left:-406,
                   top:100,
                   opacity:1,
                   z:2
               },
               {
                   width:300,
                   height:200,
                   left:-166,
                   top:79,
                   opacity:0.8,
                   z:3
               },
               {
                   width:400,
                   height:260,
                   left:0,
                   top:20,
                   opacity:1,
                   z:4
               },
               {
                   width:300,
                   height:200,
                   left:300,
                   top:79,
                   opacity:0.8,
                   z:3
               },
               {
                   width:260,
                   height:180,
                   left:580,
                   top:100,
                   opacity:1,
                   z:2
               }
           ]
           //设置li定位
           fnMove()
           //上一个按钮
           $slidepic.find('.prev').on('click',function(){
               if(off){
                   off = false;
                   fnMove(true)
               }
           })
           //下一个按钮
           $slidepic.find('.next').on('click',function(){
               if(off){
                   off = false;
                   fnMove(false)
               }
           })
           //li运动函数
           function fnMove(b){
               if(typeof(b) != 'undefined'){         //判断参数有没有传,没有就设置li位置,传了就是按钮点击
                   if(b){
                       pos.push(pos.shift())
                   }else{
                       pos.unshift(pos.pop())
                   }
               }
               $.each(pos, function(i, val) {
                   aLi.eq(i).css('zIndex',pos[i].z).stop().animate(pos[i],500,function(){
                       off = true;
                   });
               });
           }
           //开启定时器自动播放
           timer = setInterval(function(){
               fnMove(true)
           },3000)
           //暂停继续播放,显示隐藏左右切换按钮
           $slidepic.hover(function(){
               clearInterval(timer)
               $(this).find('.hd').fadeIn();
           },function(){
               clearInterval(timer)
               timer = setInterval(function(){
                   fnMove(true)
               },5000)
               $(this).find('.hd').fadeOut();
           })
       })

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值