mirror of https://github.com/vector-im/riot-web
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>pull/21833/head
parent
2e7bd2e3f0
commit
11438aeee6
|
@ -56,6 +56,18 @@ export default class Sizer {
|
|||
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) {
|
||||
if (this.vertical) {
|
||||
item.style.height = `${Math.round(size)}px`;
|
||||
|
@ -80,9 +92,9 @@ export default class Sizer {
|
|||
offsetFromEvent(event) {
|
||||
const pos = this.vertical ? event.pageY : event.pageX;
|
||||
if (this.reverse) {
|
||||
return (this._getOffset() + this.getTotalSize()) - pos;
|
||||
return (this._getPageOffset() + this.getTotalSize()) - pos;
|
||||
} else {
|
||||
return pos - this._getOffset();
|
||||
return pos - this._getPageOffset();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue