核心提示:/** * Created by Administrator on 2016/12/21. *//*box.onclick = function () {move(box, height, 300, ...
/** * Created by Administrator on 2016/12/21. */ /*box.onclick = function () { move(box, "height", 300, function() { move(box, "width", 300); }); dom:标签 str:标签的属性 target:需要满足的条件 fn:调用函数 }*/ function move(dom,str,target,fn) { dom.timer = setInterval(function () { var _current = parseInt(getStyle(dom,str)); var _speed = (target - _current) / 8; if(_speed > 0){ _speed = Math.ceil(_speed); }else { _speed = 0; } if(_current == target){ clearInterval(dom.timer) if(fn){ fn(); } } dom.style[str] = _current + _speed +"px"; },10) } function getStyle(dom,styleName){ return dom.currentStyle?dom.currentStyle[styleName] :getComputedStyle(dom)[styleName]; }