Fix resizer/sizer.js mouse event offset calculation
The event coordinates are document coordinates, so the offset they are compared to should also be the document one. Signed-off-by: Pauli Virtanen <pav@iki.fi>
This commit is contained in:
parent
2e7bd2e3f0
commit
11438aeee6
1 changed files with 14 additions and 2 deletions
|
@ -56,6 +56,18 @@ export default class Sizer {
|
||||||
return this.vertical ? this.container.offsetTop : this.container.offsetLeft;
|
return this.vertical ? this.container.offsetTop : this.container.offsetLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @return {number} container offset to document */
|
||||||
|
_getPageOffset() {
|
||||||
|
let element = this.container;
|
||||||
|
let offset = 0;
|
||||||
|
while (element) {
|
||||||
|
const pos = this.vertical ? element.offsetTop : element.offsetLeft;
|
||||||
|
offset = offset + pos;
|
||||||
|
element = element.offsetParent;
|
||||||
|
}
|
||||||
|
return offset;
|
||||||
|
}
|
||||||
|
|
||||||
setItemSize(item, size) {
|
setItemSize(item, size) {
|
||||||
if (this.vertical) {
|
if (this.vertical) {
|
||||||
item.style.height = `${Math.round(size)}px`;
|
item.style.height = `${Math.round(size)}px`;
|
||||||
|
@ -80,9 +92,9 @@ export default class Sizer {
|
||||||
offsetFromEvent(event) {
|
offsetFromEvent(event) {
|
||||||
const pos = this.vertical ? event.pageY : event.pageX;
|
const pos = this.vertical ? event.pageY : event.pageX;
|
||||||
if (this.reverse) {
|
if (this.reverse) {
|
||||||
return (this._getOffset() + this.getTotalSize()) - pos;
|
return (this._getPageOffset() + this.getTotalSize()) - pos;
|
||||||
} else {
|
} else {
|
||||||
return pos - this._getOffset();
|
return pos - this._getPageOffset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue