javascript幻灯片

本文介绍了一个基于HTML和JavaScript的简易广告轮播器的实现方法。通过设置图片宽度、高度及旋转速度等参数,实现了图片的自动切换,并且可以通过点击选择特定的广告图片。
None.gif<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
None.gif
<HTML>
None.gif
<HEAD>
None.gif
<TITLE> New Document </TITLE>
None.gif
<META NAME="Generator" CONTENT="EditPlus">
None.gif
<META NAME="Author" CONTENT="">
None.gif
<META NAME="Keywords" CONTENT="">
None.gif
<META NAME="Description" CONTENT="">
None.gif
</HEAD>
None.gif

None.gif
<BODY>
None.gif
<div align="center"><div id=AdRotator></div></div>
None.gif
<SCRIPT LANGUAGE="JavaScript">
None.gif
<!--
ExpandedBlockStart.gifContractedBlock.gif
function adRotator() dot.gif{};
None.gifadRotator.initialize
=function(o)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
// script by blueDestiny
InBlock.gif

InBlock.gif
this._t = new Array();
InBlock.gif
this._l = new Array();
InBlock.gif
this._p = new Array();
InBlock.gif
this._i = new Image();
InBlock.gif
this._c = 0;
InBlock.gif
this._f = false;
InBlock.gif
this._o = o;
InBlock.gif
InBlock.gif
this._timeout = null;
InBlock.gif
this._html = "";
InBlock.gif
InBlock.gif
// configration.
InBlock.gif//
 @ image width
InBlock.gif//
 @ image height
InBlock.gif//
 @ rotator speed
InBlock.gif//
 @ filter type
InBlock.gif

InBlock.gif
this._w = 202;
InBlock.gif
this._h = 300;
InBlock.gif
this._s = 3;
InBlock.gif
this._x = 23;
InBlock.gif
InBlock.gif
return this;
ExpandedBlockEnd.gif}
;
ExpandedBlockStart.gifContractedBlock.gifadRotator.add
=function(p,t,l) dot.gifwith (this)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif_p.push(p);
InBlock.gif_t.push(t);
InBlock.gif_l.push(l);
ExpandedBlockEnd.gif}
}
;
None.gif
ExpandedBlockStart.gifContractedBlock.gifadRotator.load
=function() dot.gifwith (adRotator)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if( _i.readyState=='complete' )
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif   
if(_p.length-1==_c)
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    _f 
= true;
InBlock.gif    _c 
= 0;
InBlock.gif    window.clearTimeout(_timeout);
InBlock.gif    
//getRef("AdRotator").innerHTML="complete";
InBlock.gif
    adRotator.play();
ExpandedSubBlockEnd.gif   }

InBlock.gif   
else
ExpandedSubBlockStart.gifContractedSubBlock.gif   
dot.gif{
InBlock.gif    _c
++;
InBlock.gif    getRef(_o).innerHTML
="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "dot.gif";
InBlock.gif    _timeout
=window.setTimeout(adRotator.load,10)
ExpandedSubBlockEnd.gif   }

ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif   getRef(_o).innerHTML
="total images " + _p.length + ", loading picture " + _c + ' ' + _i.readyState + "dot.gif";
InBlock.gif   _timeout
=window.setTimeout(adRotator.load,10)
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}
}
;
None.gif
ExpandedBlockStart.gifContractedBlock.gifadRotator.play
=function() dot.gifwith (adRotator)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif
if( _f )
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif_html 
= "";
InBlock.gif_html 
+= '<table style="border:0px solid #333333;" bgcolor="#ff0000"><tr><td style="font-size:9pt;font-family:tahoma;font-weight:bold;">'
InBlock.gif_html 
+= '<div id="rotatorPlayer"'
InBlock.gif    
+ ' style="width:' + _w + ''
InBlock.gif    
+ ';height:"' + _h + '"'
InBlock.gif    
+ '>'
InBlock.gif_html 
+= '<a href="' + ( _l[_c] ? _l[_c] : "javascript:void(0);" ) + '">';
InBlock.gif_html 
+= '<img id="rotatorPic" src="' + _p[_c] + '"'
InBlock.gif    
+ ' width="' + _w + '"'
InBlock.gif    
+ ' height="' + _h + '"'
InBlock.gif    
+ (_t[_c]?' title="' + _t[_c] + '"':'')
InBlock.gif    
+ ' style="border:1px solid blue;FILTER:revealTrans(transition=' + _x + ',duration=1);"'
InBlock.gif    
+ ' >';
InBlock.gif
InBlock.gif_html 
+= '</a>';
InBlock.gif_html 
+= "</div>";
InBlock.gif_html 
+= '<div align="right">';
InBlock.gif_html 
+= '<span style="height:23px"></span>';
InBlock.gif
for(var i=0; i<_p.length; i++)
InBlock.gif   _html 
+= '<span'
InBlock.gif      
+ ' style="border:1px solid #333333;padding:1px;height:20px;text-align:center;cursor:'
InBlock.gif      
+ (_c==? ('default;background-color:red;"') : 'hand;" onclick="adRotator.select(' + i + ')"')
InBlock.gif      
+ '>'
InBlock.gif      
+ (i>8?(i+1):('0'+(i+1)))+ '</span> ';
InBlock.gif_html 
+= '<span style="height:25px"></span>';
InBlock.gif_html 
+= (_t[_c]?('<div align="center">' + (_c+1+ '' + _t[_c] + '</div>'):'<p></p>');
InBlock.gif_html 
+= "</div></td></tr></table>";
InBlock.gifgetRef(_o).innerHTML 
= _html;
InBlock.gif
InBlock.gifgetRef(
"rotatorPic").filters[0].Apply();
InBlock.gifgetRef(
"rotatorPic").filters[0].Play();
InBlock.gif
InBlock.gifnext();
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif   _i.src 
= _p[_c];
InBlock.gif   adRotator.load();
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}
}
;
ExpandedBlockStart.gifContractedBlock.gifadRotator.next
=function() dot.gifwith (this)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif(_p.length
-1==_c) ? _c=0 : _c++;
InBlock.gif_timeout
=window.setTimeout(adRotator.play,_s*1000);
ExpandedBlockEnd.gif}
}
;
ExpandedBlockStart.gifContractedBlock.gifadRotator.select
=function(i) dot.gifwith (this)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifwindow.clearTimeout(_timeout);
InBlock.gif_c
=i;
InBlock.gifadRotator.play();
ExpandedBlockEnd.gif}
}
;
ExpandedBlockStart.gifContractedBlock.gifadRotator.set
=function(second) dot.gifwith (this)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gifwindow.clearTimeout(_timeout);
InBlock.gif
if((/\d+/).test(second)==true)
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif   _s
=second;
InBlock.gif   adRotator.play();
ExpandedSubBlockEnd.gif}

InBlock.gif
else
ExpandedSubBlockStart.gifContractedSubBlock.gif
dot.gif{
InBlock.gif   alert(
"must be digit!")
InBlock.gif   adRotator.play();
ExpandedSubBlockEnd.gif}

ExpandedBlockEnd.gif}
}
;
None.gif
function getRef(id)
ExpandedBlockStart.gifContractedBlock.gif
dot.gif{
InBlock.gif
return (document.all?document.all(id):document.getElementById(id));
ExpandedBlockEnd.gif}

None.gifadRotator.initialize(
"AdRotator");
None.gif
None.gifadRotator.add(
"http://img1.qq.com/ent/20060218/3215110.jpg","aa","http://www.blueidea.com")
None.gifadRotator.add(
"http://img1.qq.com/ent/20060218/3215111.jpg","bb","http://www.baidu.com");
None.gifadRotator.add(
"http://img1.qq.com/ent/20060218/3215112.jpg")
None.gifadRotator.add(
"http://img1.qq.com/ent/20060218/3215113.jpg")
None.gifadRotator.add(
"http://img1.qq.com/ent/20060218/3215114.jpg")
None.gif
None.gifadRotator.play();
None.gif
//-->
None.gif
</SCRIPT>
None.gif
</BODY>
None.gif
</HTML>
None.gif

转载于:https://www.cnblogs.com/jinweida/archive/2008/07/07/1237345.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值