可控制左右循环翻滚的图片展示特效代码javascript

/ / 2016-01-29   阅读:2499
演示效果: 实现代码: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> <title>可控制左右翻滚的图片展示特效代...

演示效果:


实现代码:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<title>可控制左右翻滚的图片展示特效代码</title>
<style type="text/css">
*{margin:0;padding:0;}
  ul{list-style:none}
  #wrap{width:600px;border:1px solid orange;height:100px;overflow:hidden;float:left;}
  #a li,#b li{float:left;width:110px;background:red;height:100px;margin-left:10px}
  #scrolls{width:200%;float:left;}
  #a,#b{float:left;}
  .left,.right{width:20px;height:100px;line-height:100px;background:yellow;cursor:pointer;float:left;}
</style>
</head>
<body>
<div class="left" id="left" onclick="left()"><<</div>
  <div id="wrap">
   <div id="scrolls">
    <div id="a">
     <ul>
      <li>22</li>
      <li></li>
      <li></li>
      <li></li>
      <li>11</li>
     </ul>
    </div>
    <div id="b">
    </div>
   </div>
   <script type="text/javascript">
      var $ = function(id){return document.getElementById(id)};
      var wrap = $("wrap");
      var a = $("a");
      var b = $("b");
      var show = $("show");
      var d;
      b.innerHTML = a.innerHTML;
      function scrolls(){
      d = "n";
        if(b.offsetWidth - wrap.scrollLeft <=0){
         wrap.scrollLeft = wrap.scrollLeft - b.offsetWidth;
        }
        else{
         wrap.scrollLeft++;
        }
      }
      
      t = setInterval("scrolls()",10)
      
      function backScrolls(){
        if(wrap.scrollLeft <=0){
         wrap.scrollLeft = wrap.scrollLeft + b.offsetWidth;
        }
        else{
         wrap.scrollLeft--;
        }
      }
      function left(){
        d = "n";
        clearT();
        t = setInterval("scrolls()",10);
      }
      function right(){
        d = "m";
        clearT();
        t = setInterval("backScrolls()",10);
      }
      function clearT(){
       clearInterval(t);
      }
      function runs(){
        if(d == "n"){
          left();
        }
        else{
          right();
        }
      }
      wrap.onmouseover = function (){
        clearT();
      }
      wrap.onmouseout = function(){
        runs();
      }
   </script>
  </div>
<div class="right" id="right" onclick="right()">>></div>
</body>
</html>


我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈