图片抖动
程序员文章站
2024-03-26 08:03:30
...
<!--图片地址,请您自己更改!-->
<img src="http://www.qqbye.com/wawa/UploadFiles_3996/200807/2008071904350239_S.jpg" style="position:relative;" onMouseOver="init(this);rattleimage()" onMouseOut="stoprattle(this)" />
<script language="JavaScript">
var rector=3; // 抖动的幅度
var stopit=0;
var a=1;
function init(which){
stopit=0;
shake=which;
shake.style.left=0;
shake.style.top=0;
}
function rattleimage(){
if ((!document.all&&!document.getElementById)||stopit==1)
return
if (a==1){
shake.style.top=parseInt(shake.style.top)+rector
}
else if (a==2){
shake.style.left=parseInt(shake.style.left)+rector
}
else if (a==3){
shake.style.top=parseInt(shake.style.top)-rector
}
else{
shake.style.left=parseInt(shake.style.left)-rector
}
if (a<4)
a++
else
a=1
setTimeout("rattleimage()",50) // 抖动的频率
}
function stoprattle(which){
stopit=1;
which.style.left=0;
which.style.top=0;
}
</script>
图片和浏览器的抖动
<style>
#qq{position:relative;}
</style>
<script>
mfx = function(isWin){
var t = 0,z = 3,del = function(){clearInterval(mfx.ID);return mfx};
del().ID = setInterval(function(){
var i = t/180*Math.PI,x = Math.sin(i)*z,y = Math.cos(i)*z,s = qq.style;
isWin ? window.moveBy(x,y) : (s.top=x+'px',s.left=y+'px');
if((t += 90) > 1080)del();
},30);
}
</script>
<button onclick="mfx()">QQ</button>
<button onclick="mfx(1)">browser</button>
<img id="qq" src="http://dl.iteye.com/upload/picture/pic/57029/fe8a74ac-add2-396d-a298-2954c162bfe7.gif" />
上一篇: 本地缓存同步的一个简单方案
下一篇: Java学习之路(五):方法定义和调用