因为浏览器升级修改了zoom导致
https://developer.chrome.google.cn/release-notes/128?hl=zh_tw
可根据zoom值计算相差偏移量
const isChromeHighVersion = () => {
const ua = navigator.userAgent.toLowerCase();
const chromeIndex = ua.indexOf('chrome');
if (chromeIndex > -1) {
const version = ua.substring(chromeIndex + 7);
const majorVersion = parseInt(version.split('.')[0], 10);
return majorVersion > 127;
}
return false;
};
function zoomPlugin() {
const originalGetBoundingClientRect = Element.prototype.getBoundingClientRect;
if(!isChromeHighVersion()){
return;
}
Element.prototype.getBoundingClientRect = function () {
const rect = originalGetBoundingClientRect.call(this);
const zoom = Number(document.body.style.zoom || 1);
const newRect = new DOMRect(
// 可自行修改
rect.x / zoom + 100,
rect.y / zoom + 100,
rect.width / zoom,
rect.height / zoom,
);
return newRect;
};
}
调用zoomPlugin方法即可