码迷,mamicode.com
首页 > Web开发 > 详细

20160617 html5学习代码(banner滚屏不用插件版)

时间:2016-06-17 21:06:50      阅读:359      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>单页-01</title>
    <script src="js/jquery.js"></script>
        
   
    <style>
      *{margin:0;padding: 0}
      html{
          width:100%;
        
      }
      body{
          width: 100%;
      }
      #banner{
          width: 100%;
      }
      #banner ul{
          width: 100%;
      }
      #banner ul li{
          list-style: none;
      }
      #banner ul li img{
          display: block;
          width: 100%;
      }
      #banner .pre,#banner .next{
          left: 5%;
          top: 50%;
          position: absolute;
          width: 40px;
          height: 40px;
          background: rgba(230,230,230,0.5) url(../images/slider-left.png) no-repeat center center;         
          
      }
      #banner .next{
          right: 5%;
          left: auto;
          background: rgba(230,230,230,0.5) url(../images/slider-right.png) no-repeat center center;   
      }
      
    </style>
</head>
<body>
    <header>
        <div id="banner">
            <ul>
                <li><a href="#"><img src="images/t-1.png" ></a></li>                              
            </ul>
              <a class="pre" href="javascript:;"></a>
              <a class="next" href="javascript:;"></a>
        </div>   
    </header>
    
    <script>
        var i=1;
        var t=null;
         function auto(){
            t=setInterval(function(){
                i++;
                if(i>2){
                    i=1;
                }
                $(‘#banner ul li img‘).attr(‘src‘,‘images/t-‘+i+‘.png‘);
            },2000);
         }
           auto();
         $(‘#banner ul li img‘).hover(function(){
             clearInterval(t);
         },function(){
             auto();
         })
         
         $(‘.next,.pre‘).hover(function(){clearInterval(t)},function(){auto()});
         $(‘.next‘).click(function(){
             i++;
             if(i>2){
                 i=1;
             }
             $(‘#banner ul li img‘).attr(‘src‘,‘images/t-‘+i+‘.png‘);
         })
           $(‘.prev‘).click(function(){
            i--;
            if(i<1){
                    i=2;
            }
            $("#banner ul li img").attr(‘src‘,‘images/t-‘+i+‘.png‘);
        })
        
    </script>
</body>
</html>

20160617 html5学习代码(banner滚屏不用插件版)

标签:

原文地址:http://www.cnblogs.com/liaoliao985786516/p/5595097.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!