fix: 大屏触控优化——①点击错位:ctrl-img object-fit:contain 时图片绘制区小于盒子(居中黑边),坐标换算改为按实际绘制区域,黑边点击忽略;②滑动卡顿:tap/swipe/key/text 每次 u2.connect 重建连接(1-3s 握手),加 60s 连接缓存,失败自动清缓存重建(实测点击 2.97s→1.13s)
This commit is contained in:
@@ -391,14 +391,18 @@ function updateCtrlHead(){
|
||||
document.getElementById('ctrl-sub').textContent=_ctrlSerial+(d.present?'':'(离线)');
|
||||
}
|
||||
// 坐标映射:显示尺寸 -> 设备原生分辨率
|
||||
// 图片 object-fit:contain 时实际绘制区域小于盒子(居中留黑边),
|
||||
// 必须按绘制区域换算,否则黑边/偏移导致点击错位
|
||||
function ctrlCoords(ev){
|
||||
const img=document.getElementById('ctrl-img');
|
||||
if(!img.naturalWidth)return[null,null];
|
||||
if(!img.naturalWidth||!img.naturalHeight)return[null,null];
|
||||
const r=img.getBoundingClientRect();
|
||||
return[
|
||||
Math.round((ev.clientX-r.left)/r.width*img.naturalWidth),
|
||||
Math.round((ev.clientY-r.top)/r.height*img.naturalHeight),
|
||||
];
|
||||
const scale=Math.min(r.width/img.naturalWidth,r.height/img.naturalHeight);
|
||||
const drawW=img.naturalWidth*scale, drawH=img.naturalHeight*scale;
|
||||
const ox=(r.width-drawW)/2, oy=(r.height-drawH)/2; // contain 偏移
|
||||
const px=ev.clientX-r.left, py=ev.clientY-r.top;
|
||||
if(px<ox||px>ox+drawW||py<oy||py>oy+drawH)return[null,null]; // 黑边点击忽略
|
||||
return[Math.round((px-ox)/scale),Math.round((py-oy)/scale)];
|
||||
}
|
||||
function ctrlTap(x,y){
|
||||
if(x==null||!x)return;
|
||||
|
||||
Reference in New Issue
Block a user