您的位置:首页 > Web前端 > JavaScript

js幻灯片播放器

2008-07-23 18:17 316 查看
前台HTML如下:

<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>轻量封装图片轮动</title>
<style type="text/css">
<!--
body { font-size:12px;
}
input {
border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
button {
border-right: #7b9ebd 1px solid;
padding-right: 2px;
border-top: #7b9ebd 1px solid;
padding-left: 2px;
font-size: 12px;
filter: progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr=#ffffff, EndColorStr=#cecfde);
border-left: #7b9ebd 1px solid;
cursor: hand;
color: black;
padding-top: 2px;
border-bottom: #7b9ebd 1px solid;
}
-->
</style>
<script language="javascript" src="ui/js/adRotator.js">
</script>

</head>
<BODY onload="adRotator.loads()">
<div id="rotatorPlayer"></div>

<input type="button" name="play" value="开始播放" onclick="adRotator.play()" disabled="disabled"/>
<input type="button" name="stops" value="暂停" onclick="adRotator.stops()" />
<input type="button" name="backs" value="上一张" disabled="disabled" onclick="adRotator.backs()"/>
<input type="button" name="next" value="下一张" onclick="adRotator.next()"/>
<input type="text" id="second" value="3" size="3" maxlength="2">

<input type="button" value="设置时间" />

<input name="image" type="text" size="65"/>
<script language="javascript">
/* 添加图片,还要加的话注意图片名字就好了,后面400,300是大小 */
adRotator.add("files/ArticleImg/$2008722489.jpg",400,300);
adRotator.add("files/ArticleImg/004761.jpg",400,300);
adRotator.add("files/ArticleImg/008060.jpg",400,300);
</script>
</BODY>

</html>

adRotator.js文件:

var _c = 0;
var _i = 0;
var _v = 1;
var _l = 0;
var _sf = 3000;
var _html = null;
var _image = null;
var _mycars= new Array();
var _w = new Array();
var _h = new Array();

function adRotator() {}

function adRotator.add(p,w,h)
{
_mycars[_c] = p;
_w[_c] = w;
_h[_c] = h;
_c = _c + 1;
}

/* 播放设置 */
function adRotator.loads()
{
_html = '<img src="' + _mycars[_i] + '" width="' + _w[_i] + '" height="' + _h[_i] + '" style="border:1px solid #CCCCCC;">'
document.getElementById('image').value = _html + ',' + _i;
document.getElementById('rotatorPlayer').innerHTML = _html;
if (_i < _mycars.length && _l < 1)
{
if (_v < 1)
{
_i = _i + 1;
document.getElementById('stops').disabled='';
document.getElementById('play').disabled='True';
document.getElementById('backs').disabled='True';
document.getElementById('next').disabled='True';
window.setTimeout("adRotator.loads("+_i+")",_sf);
}
else
{
document.getElementById('stops').disabled='True';
document.getElementById('play').disabled='';
document.getElementById('backs').disabled='';
document.getElementById('next').disabled='';
}
}
// else
// {
// _html = '<img src="' + _mycars[_i] + '" width="' + _w[_i] + '" height="' + _h[_i] + '" style="border:1px solid #CCCCCC;">'
// document.getElementById('image').value = _html + ',' + _i;
// document.getElementById('rotatorPlayer').innerHTML = _html;
// }
if (_i+1 > _mycars.length)
{
document.getElementById('stops').disabled='True';
document.getElementById('play').disabled='';
document.getElementById('backs').disabled='';
document.getElementById('next').disabled='True';
_i = _i-1;
_l=1;
_v = 1;
}
}

/* 播放 */
function adRotator.play()
{
_v = 0;
_l = 0;
_i=0;
adRotator.loads();
}

/* 下一张 */
function adRotator.next()
{
_l = 1;
if(_i+1 < _mycars.length)
{
_i = _i + 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('backs').disabled='';
adRotator.loads();
}
else
{
document.getElementById('next').disabled='True';
}
}

/* 上一张 */
function adRotator.backs()
{
_l = 1;
if(_i-1 < 0)
{
document.getElementById('backs').disabled='True';
}
else
{
_i = _i - 1;
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('next').disabled='';
document.getElementById('backs').disabled='';
adRotator.loads();
}
}

/* 间隔时间 */
function adRotator.set()
{
var _sfc = document.getElementById('second').value;
if (isInteger(_sfc))
{
_sf = _sfc * 1000;
}
else
{
alert('提示:只能输入数字!');
document.getElementById('second').value=1;
document.getElementById('second').select();
}
}

/* 字符检测 */
function isInteger(str)
{
var regu = /^[-]{0,1}[0-9]{1,}$/;
return regu.test(str);
}

/* 暂停 */
function adRotator.stops()
{
_v = 1;
if (_i >= _mycars.length)
{
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('backs').disabled='';
}
else if(_i-1 <= 0)
{
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('next').disabled='';

}
else
{
document.getElementById('play').disabled='';
document.getElementById('stops').disabled='True';
document.getElementById('next').disabled='';
document.getElementById('backs').disabled='';
}
_i=_i-1;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: