如下的代码是进行banner图片切换的html 代码和 相应的js 文件,图片的切换速度是固定的,现在希望用户可以控制图片的切换速度 ,给快中慢三种选择,该怎么改啊 <script language="javascript" type="text/javascript">var $ = function (id) {
return "string" == typeof id ? document.getElementById(id) : id;
};var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}}
Object.extend = function(destination, source)
{
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var TransformView = Class.create();
TransformView.prototype = {
initialize: function(container, slider, parameter, count, options) {
if(parameter <= 0 || count <= 0) return;
var oContainer = $(container);
var oSlider = $(slider);
var oThis = this;
this.Index = 0;
this._timer = null;
this._slider = oSlider;
this._parameter = parameter;
this._count = count || 0;
this._target = 0;
this.SetOptions(options);
this.Up = !!this.options.Up;
this.Step = Math.abs(this.options.Step);
this.Time = Math.abs(this.options.Time);
this.Auto = !!this.options.Auto;
this.Pause = Math.abs(this.options.Pause);
this.onStart = this.options.onStart;
this.onFinish = this.options.onFinish;
oContainer.style.overflow = "hidden";
oContainer.style.position = "relative";
oSlider.style.position = "absolute";
oSlider.style.top = oSlider.style.left = 0;
},
SetOptions: function(options) {
this.options = {
Up: true,
Step: 4,
Time: 10,
Auto: true,
Pause: 1500,
onStart: function(){},
onFinish: function(){}
};
Object.extend(this.options, options || {});
},
Start: function() {
if(this.Index < 0){
this.Index = this._count - 1;
} else if (this.Index >= this._count){
//this.Index = 0;
}
this._target = -1 * this._parameter * this.Index;
this.onStart();
this.Move();
},
Move: function() {
clearTimeout(this._timer);
var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
if (iStep != 0) {
this._slider.style[style] = (iNow + iStep) + "px";
this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
} else {
if (this.Index >= this._count){
this.Index = 0;
this._target = 0;
}
this._slider.style[style] = this._target + "px";
this.onFinish();
if (this.Auto) {
this._timer = setTimeout(function(){
oThis.Index++; oThis.Start();
},
this.Pause);
}
}
},
GetStep: function(iTarget, iNow) {
var iStep = (iTarget - iNow) / this.Step;
if (iStep == 0) return 0;
if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
return iStep;
},
Stop: function(iTarget, iNow) {
clearTimeout(this._timer);
this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
}
};window.onload=function(){
function Each(list, fun){
for (var i = 0, len = list.length; i < len; i++) {
fun(list[i], i);
}
}; ////////////////////////test2
var objs2 = $("idNum2").getElementsByTagName("li");
var tv2 = new TransformView("idTransformView2", "idSlider2", 959, 4, {
onStart: function(){ Each(objs2, function(o, i){
var idx = tv2.Index;
if(idx >= tv2._count){
idx = 0;
}
o.className = idx == i ? "on" : ""; })
},
Up: false
});
tv2.Start();
Each(objs2, function(o, i){
o.onmouseover = function(){
o.className = "on";
tv2.Auto = false;
tv2.Index = i;
tv2.Start();
}
o.onmouseout = function(){
o.className = "";
tv2.Auto = true;
tv2.Start();
}
})
}</script>
<div class="main1">
<div class="baner1">
<DIV class="container" id=idTransformView2>
<UL class="slider slider2" id=idSlider2>
<LI><A href="<%=scr1 %>" target=_blank><IMG
src="<%=path1 %>" border=0></A> </LI>
<LI><A href="<%=scr2 %>"
target=_blank><IMG
src="<%=path2 %>"
border=0></A> </LI>
<LI><A href="<%=scr3 %>"
target=_blank><IMG
src="<%=path3 %>"
border=0></A> </LI>
<LI><A href="<%=scr4 %>" target=_blank><IMG
src="<%=path4 %>"
border=0></A> </LI>
<LI><A href="<%=scr1 %>" target=_blank><IMG
src="<%=path1%>" border=0></A> </LI></UL>
<UL class=num id=idNum2>
<LI>1</LI>
<LI>2</LI>
<LI>3</LI>
<LI>4<!-- <li>5</li><li>6</li><li>7</li>-->
</LI></UL>
</DIV>
</div>
</div>
return "string" == typeof id ? document.getElementById(id) : id;
};var Class = {
create: function() {
return function() {
this.initialize.apply(this, arguments);
}
}}
Object.extend = function(destination, source)
{
for (var property in source) {
destination[property] = source[property];
}
return destination;
}
var TransformView = Class.create();
TransformView.prototype = {
initialize: function(container, slider, parameter, count, options) {
if(parameter <= 0 || count <= 0) return;
var oContainer = $(container);
var oSlider = $(slider);
var oThis = this;
this.Index = 0;
this._timer = null;
this._slider = oSlider;
this._parameter = parameter;
this._count = count || 0;
this._target = 0;
this.SetOptions(options);
this.Up = !!this.options.Up;
this.Step = Math.abs(this.options.Step);
this.Time = Math.abs(this.options.Time);
this.Auto = !!this.options.Auto;
this.Pause = Math.abs(this.options.Pause);
this.onStart = this.options.onStart;
this.onFinish = this.options.onFinish;
oContainer.style.overflow = "hidden";
oContainer.style.position = "relative";
oSlider.style.position = "absolute";
oSlider.style.top = oSlider.style.left = 0;
},
SetOptions: function(options) {
this.options = {
Up: true,
Step: 4,
Time: 10,
Auto: true,
Pause: 1500,
onStart: function(){},
onFinish: function(){}
};
Object.extend(this.options, options || {});
},
Start: function() {
if(this.Index < 0){
this.Index = this._count - 1;
} else if (this.Index >= this._count){
//this.Index = 0;
}
this._target = -1 * this._parameter * this.Index;
this.onStart();
this.Move();
},
Move: function() {
clearTimeout(this._timer);
var oThis = this, style = this.Up ? "top" : "left", iNow = parseInt(this._slider.style[style]) || 0, iStep = this.GetStep(this._target, iNow);
if (iStep != 0) {
this._slider.style[style] = (iNow + iStep) + "px";
this._timer = setTimeout(function(){ oThis.Move(); }, this.Time);
} else {
if (this.Index >= this._count){
this.Index = 0;
this._target = 0;
}
this._slider.style[style] = this._target + "px";
this.onFinish();
if (this.Auto) {
this._timer = setTimeout(function(){
oThis.Index++; oThis.Start();
},
this.Pause);
}
}
},
GetStep: function(iTarget, iNow) {
var iStep = (iTarget - iNow) / this.Step;
if (iStep == 0) return 0;
if (Math.abs(iStep) < 1) return (iStep > 0 ? 1 : -1);
return iStep;
},
Stop: function(iTarget, iNow) {
clearTimeout(this._timer);
this._slider.style[this.Up ? "top" : "left"] = this._target + "px";
}
};window.onload=function(){
function Each(list, fun){
for (var i = 0, len = list.length; i < len; i++) {
fun(list[i], i);
}
}; ////////////////////////test2
var objs2 = $("idNum2").getElementsByTagName("li");
var tv2 = new TransformView("idTransformView2", "idSlider2", 959, 4, {
onStart: function(){ Each(objs2, function(o, i){
var idx = tv2.Index;
if(idx >= tv2._count){
idx = 0;
}
o.className = idx == i ? "on" : ""; })
},
Up: false
});
tv2.Start();
Each(objs2, function(o, i){
o.onmouseover = function(){
o.className = "on";
tv2.Auto = false;
tv2.Index = i;
tv2.Start();
}
o.onmouseout = function(){
o.className = "";
tv2.Auto = true;
tv2.Start();
}
})
}</script>
<div class="main1">
<div class="baner1">
<DIV class="container" id=idTransformView2>
<UL class="slider slider2" id=idSlider2>
<LI><A href="<%=scr1 %>" target=_blank><IMG
src="<%=path1 %>" border=0></A> </LI>
<LI><A href="<%=scr2 %>"
target=_blank><IMG
src="<%=path2 %>"
border=0></A> </LI>
<LI><A href="<%=scr3 %>"
target=_blank><IMG
src="<%=path3 %>"
border=0></A> </LI>
<LI><A href="<%=scr4 %>" target=_blank><IMG
src="<%=path4 %>"
border=0></A> </LI>
<LI><A href="<%=scr1 %>" target=_blank><IMG
src="<%=path1%>" border=0></A> </LI></UL>
<UL class=num id=idNum2>
<LI>1</LI>
<LI>2</LI>
<LI>3</LI>
<LI>4<!-- <li>5</li><li>6</li><li>7</li>-->
</LI></UL>
</DIV>
</div>
</div>
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货