看我压缩后的JS代码:
function jqShake(elm) { var $elm = $(elm); if (!$elm.length) return; var obj = $elm[0], left = obj.offsetLeft, top = obj.offsetTop; obj.style.left = obj.offsetLeft + 'px'; obj.style.top = obj.offsetTop + 'px'; obj.style.position = 'absolute'; obj.style.margin = 0; var click = function() { var cn = parseInt($elm.attr('data-shake-cn') || 30); if (cn < 2) { obj.style.left = left + 'px'; obj.style.top = top + 'px'; $elm.attr('data-shake-cn', 30); return console.log('cn end...'); } obj.style.left = left + ((cn % 2) > 0 ? -2 : 2) + 'px'; obj.style.top = top + ((cn % 2) > 0 ? -2 : 2) + 'px'; $elm.attr('data-shake-cn', --cn); setTimeout(click, 30); } obj.onclick = click; } window.onload = function() { jqShake('#bk'); }回复
哈哈哈! 以为女人主动找你似的。基于IE6真是必须点赞。如果是我,一定是用animation
回复