JavaScript qq窗口抖动效果

来源:互联网 发布:湘潭软件职业技术学院 编辑:程序博客网 时间:2024/06/03 10:38
部分的代码限于博客限制,无法出现,请自行补充
#box {width:600px;height:500px;border:1px solid #f00;margin:0auto;position:relative;}
#top{width:200px;height:200px;background:#0f0;position:absolute;left:200px;top:150px;}
#button {position:absolute;left:280px;top:370px;}
window.onload = function () {
var button = document.getElementByIdx_x_x("button");
var top = document.getElementByIdx_x_x("top");
var timer = null;
var a = ["top","left"];
var b = 0;
var s = 0;

button.onclick = function (){
clearInterval(timer);
timer = setInterval(function () {
s = b%2;
top.style[a[s]] = change();
if (b>99) {
clearInterval(timer);
b = 0;
}
},10);
}
function change() {
if ((b++)%4 < 2) {
if (s == 0) {
return 160+"px";
}
return 210+"px"; 
}else {
if (s == 0) {
return 150+"px";
}
return 200+"px";
}
}
}
 
 
 

-------------------------------------------------------------------------------------

JavaScript <wbr>qq窗口抖动效果
-----------------------------------------------------------------------------------------------

学到了一个新的写法:可以把属性写到数组里面,再在style里面赋值。。。。图片 28 行
0 0
原创粉丝点击