您现在的位置:首页 >> 前端 >> 内容

无缝连接封装

时间:2016/12/30 9:31:57 点击:

  核心提示:/** * 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];
}

作者:网络 来源:qq_2867647
  • 上一篇:ajax
  • 下一篇:cookie封装插件