[LayaAir 2.0]分享问题解决,关键词:canvas不在左上角,鼠标点击位置偏移怎么办
关于canvas不是 定位在左上角,导致点击事件偏移问题首先,请找到代码initevent
initEvent(e, nativeEvent = null) {主要是获取当前 包裹层 Browser._container的偏移位置, window的滚动数值,以及document的偏移位置,
var _this = this;
_this._event._stoped = false;
_this._event.nativeEvent = nativeEvent || e;
_this._target = null;
var docElem = document.documentElement
var win = document.defaultView
var clientBox = Browser._container.getBoundingClientRect()
this._point.setTo((e.pageX || e.clientX)-clientBox.x - win.pageXOffset - docElem.clientLeft,(e.pageY || e.clientY)-clientBox.y - win.pageYOffset - docElem.clientTop);
// this._point.setTo(e.pageX || e.clientX, e.pageY || e.clientY);
if (this._stage._canvasTransform) {
this._stage._canvasTransform.invertTransformPoint(this._point);
_this.mouseX = this._point.x;
_this.mouseY = this._point.y;
}
_this._event.touchId = e.identifier || 0;
this._tTouchID = _this._event.touchId;
var evt;
evt = TouchManager.I._event;
evt._stoped = false;
evt.nativeEvent = _this._event.nativeEvent;
evt.touchId = _this._event.touchId;
}
没有找到相关结果
已邀请:
要回复问题请先登录
0 个回复