日期:2014-05-16  浏览次数:20338 次

js图片切换特效
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>JavaScript 图片切换展示效果</title>
</head>
<body>
<style type="text/css"> 
.container, .container *{margin:0; padding:0;} .container{width:408px; height:168px; overflow:hidden;position:relative;}.slider{position:absolute;}
.slider li{ list-style:none;display:inline;}
.slider img{ width:408px; height:168px; display:block;}.slider2{width:2000px;}
.slider2 li{float:left;}.num{ position:absolute; right:5px; bottom:5px;}
.num li{
float: left;
color: #FF7300;
text-align: center;
line-height: 16px;
width: 16px;
height: 16px;
font-family: Arial;
font-size: 12px;
cursor: pointer;
overflow: hidden;
margin: 3px 1px;
border: 1px solid #FF7300;
background-color: #fff;
}
.num li.on{
color: #fff;
line-height: 21px;
width: 21px;
height: 21px;
font-size: 16px;
margin: 0 1px;
border: 0;
background-color: #FF7300;
font-weight: bold;
}
</style>
<div class="container" id="idTransformView">
<ul class="slider" id="idSlider">
    <li><img src="image-slideshow-5\images\image1.jpg"/></li>
    <li><img src="image-slideshow-5\images\image2.jpg"/></li>
    <li><img src="image-slideshow-5\images\image3.jpg"/></li>
</ul>
<ul class="num" id="idNum">
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
</div><br /><div class="container" id="idTransformView2">
<ul class="slider slider2" id="idSlider2">
    <li><img src="image-slideshow-5\images\image1.jpg"/></li>
    <li><img src="image-slideshow-5\images\image2.jpg"/></li>
    <li><img src="image-slideshow-5\images\image3.jpg"/></li>
</ul>
<ul class="num" id="idNum2">
    <li>1</li>
    <li>2</li>
    <li>3</li>
</ul>
</div><br /><div>
<input id="idStop" type="button" value=" 停止自动 " />
<input id="idStart" type="button" value=" 开始自动 " />
<br /><br /><input id="idPre" type="button" value=" <- 上一个 " />
<input id="idNext" type="button" value=" 下一个 -> " />
<br /><br />
切换速度:
<input id="idFast" type="button" value=" + 加 速 " />
<input id="idSlow" type="button" value=" - 减 速 " />
<br /><br />
停顿时间:
<input id="idAdd" type="button" value=" + 加时间 " />
<input id="idReduce" type="button" value=" - 减时间 " />
<br /><br />
<input id="idReset" type="button" value=" Reset " />
</div><script 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), oSlider = $(slider), 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";
oCon