仿msn,qq窗体震动的层抖动效果

<!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-Language" content="zh-cn" />

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<meta name="robots" content="all" />

<title>仿msn,qq窗体震动的层抖动效果</title>

<style type="text/css">

#body
{text-align:center;}

#test
{width:325px; height:235px; position:absolute; margin:20px auto; border:2px dotted red; text-align:center}

</style>

</head>

<body>

<div style="margin:10px 200px">

<div>
<input type="button" value="开始抖动" onclick="nn.start()" />

<input type="button" value="停止抖动" onclick="nn.stop()" />

<font color="red" size="2">当然也可以设置时间,抖动多少毫秒后自动停止抖动</font>
</div>

<div id="test">

<br>

<img border="0" width="300" height="200" src="image.jpg"></div>

</div>

</body>

</html>

<script type="text/javascript">

var m=document.getElementById("test");

function SKclass (obj,Rate,speed) {

var oL=obj.offsetLeft;

var oT=obj.offsetTop;

this.stop=null;

this.oTime=null;

var om=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);

}

}

var nn=new SKclass(m,20,70);

</script>
posted @ 2011-02-17 10:41  Anrai  阅读(327)  评论(0编辑  收藏  举报