JS实现仿QQ聊天窗口抖动特效
JS实现仿QQ聊天窗口抖动特效
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
<title>JavaScript层抖动效果</title>
<styletype="text/css">
#body{text-align:center;}
#test{width:200px;position:absolute;margin:10pxauto;height:100px;border:2pxdottedred;text-align:center}
</style>
</head>
<body>
<divstyle="margin:10px200px">
<div>
<inputtype="button"value="~点这里让我抖抖吧~"onclick="nn.start()"/></div>
<div>
<inputtype="button"value="晃晕了,我不抖了!"onclick="nn.stop()"/></div>
<divid="test">
<br>
<imgborder="0"src="smiley.gif"></div>
</div>
<p></p>
<p></p>
</body>
</html>
<scripttype="text/javascript">
varm=document.getElementById("test");
functionSKclass(obj,Rate,speed){
varoL=obj.offsetLeft;
varoT=obj.offsetTop;
this.stop=null;
this.oTime=null;
varom=this;
this.start=function(){
if(parseInt(obj.style.left)==oL-2){
obj.style.top=oT+2+"px";
setTimeout(function(){obj.style.left=oL+2+"px"},Rate)
}
else{
obj.style.top=oT-2+"px";
setTimeout(function(){obj.style.left=oL-2+"px"},Rate)
}
this.oTime=setTimeout(function(){om.start()},speed);
}
this.stop=function(){
clearTimeout(this.oTime);
}
}
varnn=newSKclass(m,20,70);
</script>
</body>
</html>
再来一个更简单的
<imgid="win"style='position:relative'src="/UploadPic/2008-9/2008962512241.jpg">
<br/><br/>
<buttononclick="zd()">振动</button>
<script>
functionzd(u){
vara=['top','left'],b=0;
u=setInterval(function(){
document.getElementById('win').style[a[b%2]]=(b++)%4<2?0:4;
if(b>15){clearInterval(u);b=0}
},32)
}
</script>
以上所述就是本文的全部内容了,希望大家能够喜欢。