一个新闻轮播图

<!DOCTYPE HTML>
<html>
 <head>
  <meta charset="utf-8"/>
  <meta name="keywords" content="pt"/>
  <meta name="description" content="pt"/>
  <title>
   pt
  </title>
  <style>
   #zong{width:640px;height:349.5px;margin:100px auto;overflow:hidden;}
   #bwai{width:1932px;height:275px;}
   #bimg{width:640px;height:275px;position:absolute;}
   #swai{width:1932px;height:70.5px;} 
   .simg{width:157px;height:66.5px;float:left;margin-right:4px;margin-top:4px;}
   .red{border:2px solid red;width:153px;height:62.5px;}
   #left{width:30px;height:100px;background:gray;position:absolute;opacity:0;margin-top:100px;margin-left:30px;cursor:pointer;}
   #right{width:30px;height:100px;background:gray;position:absolute;opacity:0;margin-top:100px;margin-left:580px;cursor:pointer;}
  </style>
 </head>
 <body>
 <div id="zong">
  <div id="bwai">
   <div id="bimg"></div>
   <div id="left"></div>
   <div id="right"></div>
  </div>
  <div id="swai">
   <div class="simg" style="border:2px solid red;width:153px;height:62.5px"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
   <div class="simg"></div>
  </div>
 </div>
 <script>
  spic=new Array(
  "url(img/1.png)",
  "url(img/2.png)",
  "url(img/3.png)",
  "url(img/4.png)",
  "url(img/5.png)",
  "url(img/6.png)",
  "url(img/7.png)",
  "url(img/8.png)",
  "url(img/9.png)",
  "url(img/10.gif)",
  "url(img/11.png)",
  "url(img/12.jpg)");
  simg=document.getElementsByClassName('simg');
  bimg=document.getElementById('bimg');
  swai=document.getElementById('swai');
  bwai=document.getElementById('bwai');
  left=document.getElementById('left');
  right=document.getElementById('right');
  bimg.style.background=spic[0];
  bimg.style.backgroundSize="100%";
  for(var i=0;i<simg.length;i++){
   simg[i].id=i;
   simg[i].style.background=spic[i];
   simg[i].style.backgroundSize="100%";
   simg[i].οnmοuseοver=function(){
    num=Number(this.id);
    bh();
   }
  }
  bwai.οnmοuseοver=function(){
   lr();
   clearInterval(tt);
  }
  bwai.οnmοuseleave=function(){
   left.style.opacity="0";
   right.style.opacity="0";
   if(num<11){
    tt=setInterval(aa,2000);
   }
  }
  swai.οnmοuseοver=function(){
   clearInterval(tt);
  }
  swai.οnmοuseοut=function(){
   tt=setInterval(aa,2000);
  }
  tt=setInterval(aa,2000);
  var num=0;
  function aa(){num++;console.log(num);zz(num);}
  left.οnclick=function(){if(num==0){num=12;}console.log(num);num--;zz(num);}
  right.οnclick=function(){num++;if(num==12){num=0;}zz(num);}
  function zz(num){
   bh();
   if(num<2){swai.style.marginLeft="0px";}
   else if(num>=2 && num<11){swai.style.marginLeft="-"+161*(num-2)+"px";}
   else if(num==11){swai.style.marginLeft="-"+161*(num-3)+"px";clearInterval(tt);}
  }
  function lr(){
   left.style.opacity="0.8";
   right.style.opacity="0.8";
  }
  function bh(){
   bimg.style.backgroundImage=spic[num];
   for(var i=0;i<simg.length;i++){
    simg[i].style.border="none";
    simg[i].style.width="157px";
    simg[i].style.height="66.5px";
   }
   simg[num].style.border="2px solid red";
   simg[num].style.width="153px";
   simg[num].style.height="62.5px";
  }
 </script>
 </body>
</html>

图片:

效果图:

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值