Browse Source

Pull request #3109: 无JIRA任务 resizeObserver

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'b08014b5946ba933323d0b69bd486807d4e648b7':
  resizeObserver
es6
guy-王川 2 years ago
parent
commit
97ab9139c1
  1. 29
      src/core/platform/web/detectElementResize.js

29
src/core/platform/web/detectElementResize.js

@ -112,7 +112,21 @@
};
var addResizeListener = function (element, fn) {
if (attachEvent) {
if (window.ResizeObserver) {
if (!element.__resizeObserver__) {
var resizeObserver = new window.ResizeObserver(function () {
element.__resizeListeners__.forEach(function (listener) {
listener();
});
});
resizeObserver.observe(element);
element.__resizeObserver__ = resizeObserver;
}
if (!element.__resizeListeners__) {
element.__resizeListeners__ = [];
}
element.__resizeListeners__.push(fn);
} else if (attachEvent) {
element.attachEvent("onresize", fn);
BI.nextTick(fn);
} else {
@ -137,8 +151,17 @@
}
};
var removeResizeListener = function (element, fn) {
if (attachEvent) element.detachEvent("onresize", fn);
else {
if (window.ResizeObserver) {
var index = element.__resizeListeners__.indexOf(fn);
if (index >= 0) {
element.__resizeListeners__.splice(index, 1);
if (!element.__resizeListeners__.length) {
element.__resizeObserver__ && element.__resizeObserver__.unobserve(element);
}
}
} else if (attachEvent) {
element.detachEvent("onresize", fn);
} else {
element.__resizeListeners__.splice(element.__resizeListeners__.indexOf(fn), 1);
if (!element.__resizeListeners__.length) {
element.removeEventListener("scroll", scrollListener);

Loading…
Cancel
Save