源程序:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns=" http://www.w3.org/1999/xhtml ">
<kepala>
<meta http-equiv="Jenis Konten" content="teks/html; charset=gb2312" />
<meta http-equiv="kedaluwarsa" content="0">
<title>JavaScript幻灯片效果</title>
<gaya tipe="teks/css">
<!--
badan { ukuran font:12px;
}
masukan {
perbatasan-kanan: #7b9ebd 1px padat;
padding-kanan: 2px;
perbatasan-atas: #7b9ebd 1px padat;
padding-kiri: 2px;
ukuran font: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
perbatasan-kiri: #7b9ebd 1px padat;
kursor: tangan;
warna: hitam;
padding-atas: 2px;
perbatasan-bawah: #7b9ebd 1px padat;
}
.img {
filter:alpha(opacity=1,enabled=1) blendtrans(durasi=1);
batas:1px padat #CCCCCC;
}
-->
</gaya>
<skrip bahasa="javascript">
var aku=0;
var jumlah=0;
var _c = 0;
var _i = 0;
var _v = 0;
var _l = 0;
var _fi = 0;
var _sf = 3000;
var _html = nol;
var _gambar = nol;
var _mobil saya= Array baru();
var _w = Array baru();
var _h = Array baru();
var imgs=Array baru();
var limg=Array baru();
/* 渐隐渐现 */
fungsi transImg(aktifkan){
document.getElementById("showimg").filters.blendtrans.Apply();
document.getElementById("showimg").filters[0].enabled=aktifkan;
document.getElementById("showimg").filters.blendtrans.Play();
}
/* 加载图片 */
function chk(){
aku--;
document.getElementById("rotatorPlayer").innerHTML='<img src='+limg[0].src+'><br><br>' + '照片已加载:' + parseInt(((jumlah-
l)* 100/jumlah)).toString() + '%'
jika (l==0){
adRotator.bermain();
document.getElementById('stops').disabled='';
document.getElementById('next').disabled='';
}
}
if (dokumen.gambar){
limg[0]=Gambar baru();
limg[0].src="memuat.gif";
untuk(var i=0;i<13;i++)
{
imgs[i]=Gambar baru();
imgs[i].src=parseInt(i+1)+".jpg";
}
}
fungsi adRotator() {}
fungsi adRotator.tambahkan(p,w,h)
{
_mobil saya[_c] = p;
_w[_c] = w;
_h[_c] = jam;
_c = _c + 1;
}
/* 播放设置 */
fungsi adRotator.beban()
{
if (_i < _mobil saya.panjangnya && _l < 1)
{
_html = '<img id="showimg" src="' + _mobilsaya[_i] + '" lebar="' + _w[_i] + '" height="' + _h[_i] + '" class="img ">'
jika (_v < 1)
{
document.getElementById('image').value = _html + ',' + _i;
document.getElementById('rotatorPlayer').innerHTML = _html;
transImg(0);
_i = _i + 1;
document.getElementById('backs').disabled='';
transImg(1);
transImg(0);
window.setTimeout("adRotator.loads("+_i+")",_sf);
}
}
kalau tidak
{
_html = '<img id="showimg" src="' + _mobilsaya[_i] + '" lebar="' + _w[_i] + '" height="' + _h[_i] + '" class="img ">'
document.getElementById('image').value = _html + ',' + _i;
document.getElementById('rotatorPlayer').innerHTML = _html;
transImg(0);
transImg(1);
transImg(0);
}
if (_i+1 > _mobil saya.panjangnya)
{
document.getElementById('stops').disabled='Benar';
document.getElementById('play').disabled='';
document.getElementById('backs').disabled='';
document.getElementById('next').disabled='Benar';
_saya = 0;
_v = 1;
}
}
/* 播放 */
fungsi adRotator.play()
{
_v = 0;
_l = 0;
adRotator.beban();
}
/* 下一张 */
fungsi adRotator.next()
{
_l = 1;
if(_i+1 < _mobilsaya.panjang)
{
_i = _i + 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='Benar';
document.getElementById('backs').disabled='';
adRotator.beban();
}
kalau tidak
{
document.getElementById('next').disabled='Benar';
}
}
/* 上一张 */
fungsi adRotator.backs()
{
_l = 1;
jika(_i-1 < 0)
{
document.getElementById('backs').disabled='Benar';
}
kalau tidak
{
_i = _i - 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='Benar';
document.getElementById('next').disabled='';
adRotator.beban();
}
}
/* 间隔时间 */
fungsi adRotator.set()
{
var _sfc = document.getElementById('kedua').nilai;
jika (adalah bilangan bulat (_sfc))
{
_sf = _sfc * 1000;
}
kalau tidak
{
alert('提示:只能输入数字!');
document.getElementById('kedua').value=1;
document.getElementById('kedua').select();
}
}
/* 字符检测 */
fungsi adalah bilangan bulat (str)
{
var regu = /^[-]{0,1}[0-9]{1,}$/;
kembali regu.test(str);
}
/* 暂停 */
fungsi adRotator.berhenti()
{
_v = 1;
}
/* 添加图foto */
untuk (var i=0;i<imgs.length;i++)
{
adRotator.tambahkan(imgs[i].src,400,300);
}
</skrip>
</kepala>
<tubuh>
<tabel lebar="420" border="0" align="center" cellpadding="0" Cellspacing="0">
<tr>
<td align="tengah">
<div id="rotatorPlayer" style="text-align:center"><img src="loading.gif"><br><br>照片已加载:0%</div>
<br><br>
<input type="button" name="play" value="开始播放" onClick="adRotator.play();this.disabled='true';document.getElementById
('stops').disabled=''" dinonaktifkan = "Benar"/>
<input type="button" name="stops" value="暂停" onClick="adRotator.stops();this.disabled='true';document.getElementById
('play').disabled=''" dinonaktifkan= "Benar"/>
<input type="button" name="backs" value="上一张" onClick="adRotator.backs();" dinonaktifkan="Benar"/>
<input type="button" name="next" value="下一张" onClick="adRotator.next();" dinonaktifkan="Benar"/>
<input type="text" id="kedua" value="3" size="3" maxlength="2">
foto
<input type="button" value="设置时间" onClick="adRotator.set()" />
<br><br>
<masukan nama="gambar" type="teks" ukuran="65"/>
</td>
</tr>
</tabel>
<skrip bahasa="javascript">
jumlah=l=imgs.panjang;
untuk (var i=0;i<l;i++){
imgs[i].onload=chk;
imgs[i].onerror=chk;//无论图片是否加载成功,都执行指定方法
}
</skrip>
</tubuh>
</html>
http://www.cnblogs.com/PeriFox/archive/2006/08/09/472342.html