This commit is contained in:
X1627315083
2025-10-09 09:35:36 +08:00
parent cc8c064d9c
commit bc8e03180e
107 changed files with 0 additions and 0 deletions

48
src/utils/tools.ts Normal file
View File

@@ -0,0 +1,48 @@
function getUniversalZoomLevel() {
// 现代浏览器方案
if (window.visualViewport) {
return window.visualViewport.scale;
}
// 备用方案1
if (window.devicePixelRatio) {
return window.devicePixelRatio;
}
// 备用方案2不精确
return window.outerWidth / window.innerWidth;
}
const getMousePosition = (e:any,bor:any) => {
// if(e?.stopPropagation)e.stopPropagation()
// if(e?.preventDefault)e.preventDefault();
let event:any
if(bor){
const touch = e.changedTouches[0] as any;
event = {
offsetX:touch.clientX - e.target.getBoundingClientRect().left,
offsetY: touch.clientY - e.target.getBoundingClientRect().top,
clientX:touch.clientX,
clientY:touch.clientY,
screenX:touch.screenX,
screenY:touch.screenY,
target:e.target,
}
// if(dom){
// event.offsetX = touch.clientX - dom.getBoundingClientRect().left
// event.offsetY = touch.clientY - dom.getBoundingClientRect().top
// }
}else{
event = {
offsetX:e.offsetX,
offsetY:e.offsetY,
clientX:e.clientX,
clientY:e.clientY,
screenX:e.screenX,
screenY:e.screenY,
target:e.target,
}
}
return event
}
export {
getUniversalZoomLevel,
getMousePosition,
}