javascript實現(xiàn)淘寶幻燈片廣告展示效果
更新時間:2015年04月27日 09:04:54 作者:親愛的漢尼拔
這篇文章主要介紹了javascript實現(xiàn)淘寶幻燈片廣告展示效果的方法,以實例形式完整講述了javascript實現(xiàn)幻燈效果的javascript、css及html實現(xiàn)技巧,需要的朋友可以參考下
本文實例講述了javascript實現(xiàn)淘寶幻燈片廣告展示效果的方法。分享給大家供大家參考。具體如下:
一、效果圖如下:

二、代碼部分:
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?Math.ceil(speed):Math.floor(speed);
if(cur!=json[attr]){
oStop=false;
}
if(attr=='opacity'){
obj.style[attr]=(cur+speed)/100;
obj.style.filter="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="myscript.js"></script>
<script>
window.onload=function() {
var now = 0;
var oDiv = document.getElementById('div1');
var oOl = oDiv.getElementsByTagName('ol')[0];
var oLi = oOl.getElementsByTagName('li');
var oUl = getClass(oDiv, 'pic_body')[0];
for(var i=0;i<oLi.length;i++){
oLi[i].index=i;
oLi[i].onclick=function(){
now=this.index;
tab();
};
}
function tab(){
for(var i=0;i<oLi.length;i++){
oLi[i].className='';
}
oLi[now].className='active';
startmove(oUl,{top:-150*now});
};
function next(){
now++;
if(now==oLi.length){
now=0;
}
tab();
};
var timer=setInterval(next,3000);
oUl.onmouseover=function(){
clearInterval(timer);
};
oUl.onmouseout=function(){
timer=setInterval(next,3000);
};
}
</script>
</head>
<body>
<div id="div1">
<ol>
<li class="active">1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
</ol>
<ul class="pic_body">
<li><img src="image/1.jpg"></li>
<li><img src="image/2.jpg"></li>
<li><img src="image/3.jpg"></li>
<li><img src="image/4.jpg"></li>
<li><img src="image/5.jpg"></li>
</ul>
</div>
</body>
</html>
希望本文所述對大家的javascript程序設(shè)計有所幫助。
您可能感興趣的文章:
相關(guān)文章
基于javascript實現(xiàn)checkbox復(fù)選框?qū)嵗a
這篇文章主要介紹了基于javascript實現(xiàn)checkbox復(fù)選框?qū)嵗a,感興趣的小伙伴們可以參考一下2016-01-01
手機端 HTML5使用photoswipe.js仿微信朋友圈圖片放大效果
這篇文章主要為大家詳細(xì)介紹了移動web HTML5使用photoswipe模仿微信朋友圈圖片放大瀏覽,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
js讀寫COOKIE實現(xiàn)記住帳號或密碼的代碼(js讀寫COOKIE)
js實現(xiàn)記住帳號或密碼(js讀寫COOKIE) 的實現(xiàn)代碼,原理就是利用cookies保存于讀取功能。2010-05-05
YUI Compressor壓縮JavaScript原理及微優(yōu)化
最近寫一個jQuery插件,在最后完成優(yōu)化時,對比發(fā)現(xiàn)壓縮后文件比較大,就思考那些是可以被修改和優(yōu)化的,發(fā)現(xiàn)壓縮原理也有很大的空間可以學(xué)習(xí)2013-01-01

