Files
ColdBreeze-chat-web/src/common/polyfills.js
T
2023-05-06 16:39:31 +08:00

19 lines
555 B
JavaScript

// scrollIntoViewIfNeeded
const isSupported = "scrollIntoViewIfNeeded" in Element.prototype;
if (!isSupported) {
Element.prototype.scrollIntoViewIfNeeded = function (centerIfNeeded = true) {
const el = this;
new IntersectionObserver(function ([entry]) {
const ratio = entry.intersectionRatio;
if (ratio < 1) {
let place = ratio <= 0 && centerIfNeeded ? "center" : "nearest";
el.scrollIntoView({
block: place,
inline: place
});
}
this.disconnect();
}).observe(this);
};
}