本文实例讲述了javascript实现淘宝幻灯片广告展示效果的方法。分享给大家供大家参考。具体如下:

一、效果图如下:

javascript实现淘宝幻灯片广告展示效果

二、代码部分:

JS代码部分:

function getClass(oParent,name){ 
  var arr=[]; 
  var oBj=oParent.getElementsByTagName("*"); 
  for(var i=0;i<oBj.length;i++){ 
    if(oBj[i].className==name){ 
      arr.push(oBj[i]); 
    } 
  } 
  return arr; 
} 
function startmove(obj,json,fnEnd){ 
  var cur=0; 
  clearInterval(obj.timer); 
  obj.timer=setInterval(function(){ 
    var oStop=true; 
    for(var attr in json){ 
      if(attr=='opacity'){ 
        cur=Math.round(parseFloat(getStyle(obj,attr)*100)); 
      }else{ 
        cur=parseInt(getStyle(obj,attr)); 
      } 
      var speed=(json[attr]-cur)/10; 
      speed=speed>0"alpha(opacity:"+cur+speed+")"; 
      }else{ 
        obj.style[attr]=cur+speed+"px"; 
      } 
    } 
    if(oStop){ 
      clearInterval(obj.timer); 
      if(fnEnd)fnEnd(); 
    } 
  },30); 
 
}; 
function getStyle(obj,name){ 
  if(obj.currentStyle){ 
    return obj.currentStyle[name]; 
  }else{
    return getComputedStyle(obj,false)[name]; 
  }
};

CSS部分:

*{ margin: 0px; padding: 0px; } 
img{ 
border: none; width: 470px; height: 150px;
float: left;
} 
.pic_body li{
width: 470px; height: 150px;
float: left; z-index: 3001; } 
ul{
 list-style: none; position: absolute; top: 0px; left: 0px;
 width: 470px; height: 150px; background: yellow; z-index: 3000;
} 
#div1{ border: 1px solid black; width: 470px; height: 150px;
 position: relative; margin: 100px auto; padding: 0px;
 overflow: hidden;
} 
#div1 ol{ bottom: 10px; right: 10px; 
position: absolute; z-index: 9999; 
} 
ol li{ background: yellow; float: left; 
display: inline; margin-right: 3px; padding: 3px 4px;
position: relative; top: 0px; left: 0px;
font-family: arial; font-size: 12px;
cursor: pointer; filter: alpha(opacity:60); opacity: 0.6;
border: 1px solid black;
} 
.active{ background: yellow; font-weight: bolder;
padding: 4px 6px; filter: alpha(opacity:100); opacity: 1;
} 

HTML部分:

<!DOCTYPE html> 
<html> 
<head lang="en"> 
  <meta charset="UTF-8"> 
  <title></title> 
  <link href="css.css" rel="stylesheet" type="text/css"> 
  <script src="/UploadFiles/2021-04-02/myscript.js">

希望本文所述对大家的javascript程序设计有所帮助。

华山资源网 Design By www.eoogi.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
华山资源网 Design By www.eoogi.com