模拟google首页动画图标的

本文介绍了一种使用JavaScript实现的鼠标悬停背景图片切换效果。当鼠标悬停在一个元素上时,背景图片会逐步变化到另一种状态;当鼠标移开时,则会返回到初始状态。此效果通过设置不同的背景位置来实现平滑过渡。

 

<div id="testit" style="width:50px; height:32px; background-image:url(bg.png);background-repeat:no-repeat;background-position:0px 0px;" onmouseover="popup();" onmouseout="popdn();"></div>
<script language="javascript">
var te=0;
var te2=5;
var arrbg=new Array();
var doit
var doit1
arrbg[0]="0px 0px";
arrbg[1]="-51px 0px";
arrbg[2]="-103px 0px";
arrbg[3]="-155px 0px";
arrbg[4]="-207px 0px";
arrbg[5]="-207px 3px";

function popup(){
te=0;
doit=setInterval("pp()",50);//隔50毫秒运行pp()
}
function pp(){
if(te<=5){
document.getElementById("testit").style.backgroundPosition=arrbg[te];
te=te+1;
}
else{
clearInterval(doit);
}
}

function popdn(){
te2=5;
doit1=setInterval("pd()",50);
}
function pd(){
if(te2>=0){
document.getElementById("testit").style.backgroundPosition=arrbg[te2];
te2=te2-1;
}
else{
clearInterval(doit1);
}
}

</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值