当前位置:学会吧培训频道电脑知识学习网页制作Javascript教程javascript+css一张背景图片的不同切换» 正文

javascript+css一张背景图片的不同切换

[08-08 00:41:26]   来源:http://www.xuehuiba.com  Javascript教程   阅读:8867
概要:IT产品库 http://www.xuehuiba.com<div style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png)" index=0></div><div style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png); background-position:0px -35" index=1></div><div style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png); backgr
javascript+css一张背景图片的不同切换,标签:javascript视频教程,javascript教程下载,http://www.xuehuiba.com
IT产品库 http://www.xuehuiba.com

<div  style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png)" index=0></div>
<div  style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png); background-position:0px -35" index=1></div>
<div  style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png); background-position:0px -70" index=2></div>
<div  style=" width:50px; height:38px;background-image:url(/d/file/p/2009-09-10/20090910090847482.png); background-position:0px -107" index=3></div>
<script>
var timer=[null,null,null,null]
var g=[0,0,0,0]
var sty=[new Array(),new Array(),new Array(),new Array()] 
// http://www.knowsky.com/ 记录图片位置的数组

function touch(obj,a1,a2){
var f=0
for(var i=0;i<5;i++)
{
sty[obj.index][i]="-"+f+"px"+" "+a2+"px";
f=f+a1
}                        //循环得出图片的位置
change(obj)
}

function change(obj){
clearTimeout(timer[obj.index])             //=======
if(g[obj.index]==sty[obj.index].length-1)
{
obj.style.backgroundPosition=sty[obj.index][g[obj.index]];
timer[obj.index]=setTimeout(function(){change(obj)},100)
}
else
{
obj.style.backgroundPosition=sty[obj.index][g[obj.index]]
g[obj.index]++
timer[obj.index]=setTimeout(function(){change(obj)},100)
}
}

function restore(obj){
clearTimeout(timer[obj.index])        //================
if(g[obj.index]<1)
{clearTimeout(timer[obj.index]);
obj.style.backgroundPosition=sty[obj.index][0]
}
else
{
obj.style.backgroundPosition=sty[obj.index][g[obj.index]]
g[obj.index]--
timer[obj.index]=setTimeout(function(){restore(obj)},100)
}
}
</script>

IT产品库 http://www.xuehuiba.com
Tag:Javascript教程javascript视频教程,javascript教程下载电脑知识学习 - 网页制作 - Javascript教程
Copyright 学会吧 All Right Reserved.
在线学习社区!--学会吧
1 2 3 4 5 6 7 7 8 9 10 11 12 13