JavaScript qq窗口抖动效果

    xiaoxiao2021-04-18  55

    部分的代码限于博客限制,无法出现,请自行补充 #box {width:600px;height:500px;border:1px solid #f00;margin:0 auto;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"; } } }       ------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------- 学到了一个新的写法:可以把属性写到数组里面,再在style里面赋值。。。。图片 28 行
    转载请注明原文地址: https://ju.6miu.com/read-674938.html

    最新回复(0)