js实现同一页面可多次调用的图片幻灯切换效果
网络编程 2021-07-04 21:47www.168986.cn编程入门
这篇文章主要介绍了js实现同一页面可多次调用的图片幻灯切换效果,可实现在同一页面中多次调用幻灯切换效果,非常具有实用价值,需要的朋友可以参考下
本文实例讲述了js实现同一页面可多次调用的图片幻灯切换效果。分享给大家供大家参考。具体实现方法如下
代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://.w3./TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>js同一页面可多次调用的图片幻灯切换效果</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把狼蚁网站SEO优化代码加到<head>与</head>之间-->
<script language="javascript">
//声明命名空间
var $o = new Object();
//基础方法
$o.base = {
e:function(a,f){
for(var i=0,j=a.length;i<j;i++){f.call(a[i],i);}
}
}
$o. slide = function (id,arg){
var arg = arg||{},
t = document.getElementById(id),
a = t.getElementsByTagName("a"),
lis = [],
cl = arg.color||'#f30',
ctm = arg.time1000||2000,
w = t.clientWidth,
h = t.clientHeight,
b = ['<ul style="margin:0; padding:0; list-style:none; display:block; position:absolute; bottom:10px; right:10px;">'],
index = 0,
$ = null,
$ = null;
function change(i){
if(!!$){clearTimeout($);}
index = !isNaN(i)?i:index+1;
if(index >= a.length){index = 0;}
$o.base.e(lis,function(k){if(k == index){c(1,this);}else{c(0,this)}});
var to = - indexh;
if(a[0].offsetTop == to){
return;
}else{
if(!!$){clearInterval($);}
$ = setInterval(function(){
var ot = a[0].offsetTop;
v = Math[to<ot?'floor':'ceil']((to - ot)0.2);
if(ot == to){clearInterval($);$=null;st();}
ot += v;
a[0].style.marginTop = ot + "px";
},30)
};
}
function c(b,o){
o.style.backgroundColor = !!b?cl:"#fff";
o.style.color = !!b?"#fff":cl;
}
function st(){
if(!!$)clearTimeout($);
$ = setTimeout(function(){change()},ctm);
}
with(t.style){overflow = 'hidden';position = 'relative';}
$o.base.e(a,function(n){
this.style.display = "block";
with(this.firstChild.style){borderWidth = '0';width = w + 'px';height = h + 'px';}
b.push('<li style="width:20px; height:20px; line-height:20px; display:block; float:left; margin-left:5px; border:1px solid ' + cl + '; background-color:#fff; color:' + cl +'; font-size:14px; text-align:center; cursor:pointer;">' + (n+1) + '</li>');
});
b.push('</ul>');
t.innerHTML += b.join("");
lis = t.getElementsByTagName("li");
$o.base.e(lis,function(n){
if(n == index){c(1,this)}
this.onmouseover = function(){
if(n!=index)change(n);
}
});
st();
}
</script>
</head>
<body>
<!--把狼蚁网站SEO优化代码加到<body>与</body>之间-->
<div id="aa" style="width:402px;height:228px;">
<a href="javascript:alert('1')"><img src="/images/1.jpg"></a>
<a href="javascript:alert('2')"><img src="/images/2.jpg"></a>
<a href="javascript:alert('3')"><img src="/images/3.jpg"></a>
<a href="javascript:alert('4')"><img src="/images/4.jpg"></a>
<a href="javascript:alert('5')"><img src="/images/5.jpg"></a>
<a href="javascript:alert('6')"><img src="/images/6.jpg"></a>
<a href="javascript:alert('7')"><img src="/images/7.jpg"></a>
<a href="javascript:alert('8')"><img src="/images/8.jpg"></a>
<a href="javascript:alert('9')"><img src="/images/9.jpg"></a>
</div>
<script language="javascript">
new $o.slide("aa");
</script>
<br>
<div id="bb" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("bb",{color:'#000',time:0.2});
</script>
<br>
<div id="" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("",{color:'green'});
</script>
</body>
</html>
<html xmlns="http://.w3./1999/xhtml">
<head>
<title>js同一页面可多次调用的图片幻灯切换效果</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<!--把狼蚁网站SEO优化代码加到<head>与</head>之间-->
<script language="javascript">
//声明命名空间
var $o = new Object();
//基础方法
$o.base = {
e:function(a,f){
for(var i=0,j=a.length;i<j;i++){f.call(a[i],i);}
}
}
$o. slide = function (id,arg){
var arg = arg||{},
t = document.getElementById(id),
a = t.getElementsByTagName("a"),
lis = [],
cl = arg.color||'#f30',
ctm = arg.time1000||2000,
w = t.clientWidth,
h = t.clientHeight,
b = ['<ul style="margin:0; padding:0; list-style:none; display:block; position:absolute; bottom:10px; right:10px;">'],
index = 0,
$ = null,
$ = null;
function change(i){
if(!!$){clearTimeout($);}
index = !isNaN(i)?i:index+1;
if(index >= a.length){index = 0;}
$o.base.e(lis,function(k){if(k == index){c(1,this);}else{c(0,this)}});
var to = - indexh;
if(a[0].offsetTop == to){
return;
}else{
if(!!$){clearInterval($);}
$ = setInterval(function(){
var ot = a[0].offsetTop;
v = Math[to<ot?'floor':'ceil']((to - ot)0.2);
if(ot == to){clearInterval($);$=null;st();}
ot += v;
a[0].style.marginTop = ot + "px";
},30)
};
}
function c(b,o){
o.style.backgroundColor = !!b?cl:"#fff";
o.style.color = !!b?"#fff":cl;
}
function st(){
if(!!$)clearTimeout($);
$ = setTimeout(function(){change()},ctm);
}
with(t.style){overflow = 'hidden';position = 'relative';}
$o.base.e(a,function(n){
this.style.display = "block";
with(this.firstChild.style){borderWidth = '0';width = w + 'px';height = h + 'px';}
b.push('<li style="width:20px; height:20px; line-height:20px; display:block; float:left; margin-left:5px; border:1px solid ' + cl + '; background-color:#fff; color:' + cl +'; font-size:14px; text-align:center; cursor:pointer;">' + (n+1) + '</li>');
});
b.push('</ul>');
t.innerHTML += b.join("");
lis = t.getElementsByTagName("li");
$o.base.e(lis,function(n){
if(n == index){c(1,this)}
this.onmouseover = function(){
if(n!=index)change(n);
}
});
st();
}
</script>
</head>
<body>
<!--把狼蚁网站SEO优化代码加到<body>与</body>之间-->
<div id="aa" style="width:402px;height:228px;">
<a href="javascript:alert('1')"><img src="/images/1.jpg"></a>
<a href="javascript:alert('2')"><img src="/images/2.jpg"></a>
<a href="javascript:alert('3')"><img src="/images/3.jpg"></a>
<a href="javascript:alert('4')"><img src="/images/4.jpg"></a>
<a href="javascript:alert('5')"><img src="/images/5.jpg"></a>
<a href="javascript:alert('6')"><img src="/images/6.jpg"></a>
<a href="javascript:alert('7')"><img src="/images/7.jpg"></a>
<a href="javascript:alert('8')"><img src="/images/8.jpg"></a>
<a href="javascript:alert('9')"><img src="/images/9.jpg"></a>
</div>
<script language="javascript">
new $o.slide("aa");
</script>
<br>
<div id="bb" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("bb",{color:'#000',time:0.2});
</script>
<br>
<div id="" style="width:402px;height:228px;">
<a href="###"><img src="/images/1.jpg"></a>
<a href="###"><img src="/images/2.jpg"></a>
<a href="###"><img src="/images/3.jpg"></a>
<a href="###"><img src="/images/4.jpg"></a>
<a href="###"><img src="/images/5.jpg"></a>
</div>
<script language="javascript">
new $o.slide("",{color:'green'});
</script>
</body>
</html>
希望本文所述对大家的javascript程序设计有所帮助。
编程语言
- 如何快速学会编程 如何快速学会ug编程
- 免费学编程的app 推荐12个免费学编程的好网站
- 电脑怎么编程:电脑怎么编程网咯游戏菜单图标
- 如何写代码新手教学 如何写代码新手教学手机
- 基础编程入门教程视频 基础编程入门教程视频华
- 编程演示:编程演示浦丰投针过程
- 乐高编程加盟 乐高积木编程加盟
- 跟我学plc编程 plc编程自学入门视频教程
- ug编程成航林总 ug编程实战视频
- 孩子学编程的好处和坏处
- 初学者学编程该从哪里开始 新手学编程从哪里入
- 慢走丝编程 慢走丝编程难学吗
- 国内十强少儿编程机构 中国少儿编程机构十强有
- 成人计算机速成培训班 成人计算机速成培训班办
- 孩子学编程网上课程哪家好 儿童学编程比较好的
- 代码编程教学入门软件 代码编程教程