我正在使用 Angular 内置的颜色选择器,并且我一直在添加代码以使其在触摸屏上工作。但是,我似乎在代码的某些部分(即 mousedown 处理程序内部)遇到了障碍。每当我启动触摸事件时,都会收到无法读取未定义的属性“offset”
错误。
这也会导致桌面网络浏览器无响应 - 我无法顺利单击并拖动选择器。
这是给我错误的代码块:
Farbtastic.prototype.mousedown = function(event) {
// Capture mouse
if (!this.dragging) {
$(document).on('mousemove', this.mousemove)
.on('mouseup', this.mouseup);
this.dragging = true;
}
// Update the stored offset for the widget.
this.offset = this.$container.offset();
// Check which area is being dragged
var pos = this.widgetCoords(event);
this.circleDrag = Math.max(Math.abs(pos.x), Math.abs(pos.y)) > (this.square + 2);
// Process
this.mousemove(event);
return false;
};
我对这个问题真的很迷茫,所以非常感谢任何帮助。
最佳答案
您需要在页面加载后使用它:
$( window ).onload(function() {
this.offset = this.$container.offset();
}).bind(this);
关于javascript - 在触摸事件上获取未定义的 "Cannot read property ' 偏移量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36036361/