mirror of https://github.com/layui/layui
feat(table): 重新添加 resizeObserver (#2411)
* wip(table): auto resize * update code * chore: 移除 object 策略pull/2426/head
parent
bf9188a949
commit
29d488a0f4
|
@ -2823,6 +2823,8 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
}
|
}
|
||||||
rAF(cb);
|
rAF(cb);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
that.autoResize();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2891,7 +2893,41 @@ layui.define(['lay', 'laytpl', 'laypage', 'form', 'util'], function(exports){
|
||||||
? size.width - size.paddingLeft - size.paddingRight - size.borderLeftWidth - size.borderRightWidth
|
? size.width - size.paddingLeft - size.paddingRight - size.borderLeftWidth - size.borderRightWidth
|
||||||
: size.width
|
: size.width
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
Class.prototype.autoResize = function(){
|
||||||
|
var that = this;
|
||||||
|
|
||||||
|
that.resizeStrategy(that.elem);
|
||||||
|
}
|
||||||
|
|
||||||
|
Class.prototype.resizeStrategy = function(){
|
||||||
|
// chrome 64+
|
||||||
|
if(window.ResizeObserver){
|
||||||
|
return function(targetElem){
|
||||||
|
var that = this;
|
||||||
|
if(that.resizeObserver){
|
||||||
|
that.resizeObserver.disconnect();
|
||||||
|
that.resizeObserver = null;
|
||||||
|
}
|
||||||
|
that.resizeObserver = new ResizeObserver(function(){
|
||||||
|
that.resize();
|
||||||
|
});
|
||||||
|
that.resizeObserver.observe(targetElem[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// IE8 支持元素 resize 事件
|
||||||
|
if(lay.ie === '8'){
|
||||||
|
return function(targetElem){
|
||||||
|
var that = this;
|
||||||
|
targetElem.off('resize.lay-table-autoresize')
|
||||||
|
.on('resize.lay-table-autoresize', function(){
|
||||||
|
that.resize();
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}();
|
||||||
|
|
||||||
// 全局事件
|
// 全局事件
|
||||||
(function(){
|
(function(){
|
||||||
|
|
Loading…
Reference in New Issue