scroll.js: Use window.inner{Width,Height}

It seems with document.documentElement.client{Height,Width} we
sometimes (e.g. without <!DOCTYPE html)...) get the full element height
instead of the viewport height.

Fixes #1821.
This commit is contained in:
Florian Bruhin 2016-08-11 11:57:20 +02:00
parent aafdc225bc
commit a23f3a24b3

View File

@ -28,23 +28,23 @@ window._qutebrowser.scroll = (function() {
var y_px = window.scrollY; var y_px = window.scrollY;
if (x !== undefined) { if (x !== undefined) {
x_px = (elem.scrollWidth - elem.clientWidth) / 100 * x; x_px = (elem.scrollWidth - window.innerWidth) / 100 * x;
} }
if (y !== undefined) { if (y !== undefined) {
y_px = (elem.scrollHeight - elem.clientHeight) / 100 * y; y_px = (elem.scrollHeight - window.innerHeight) / 100 * y;
} }
/* /*
console.log(JSON.stringify({ console.log(JSON.stringify({
"x": x, "x": x,
"window.scrollX": window.scrollX, "window.scrollX": window.scrollX,
"elem.clientWidth": elem.clientWidth, "window.innerWidth": window.innerWidth,
"elem.scrollWidth": elem.scrollWidth, "elem.scrollWidth": elem.scrollWidth,
"x_px": x_px, "x_px": x_px,
"y": y, "y": y,
"window.scrollY": window.scrollY, "window.scrollY": window.scrollY,
"elem.clientHeight": elem.clientHeight, "window.innerHeight": window.innerHeight,
"elem.scrollHeight": elem.scrollHeight, "elem.scrollHeight": elem.scrollHeight,
"y_px": y_px, "y_px": y_px,
})); }));
@ -54,15 +54,15 @@ window._qutebrowser.scroll = (function() {
}; };
funcs.delta_page = function(x, y) { funcs.delta_page = function(x, y) {
var dx = document.documentElement.clientWidth * x; var dx = window.innerWidth * x;
var dy = document.documentElement.clientHeight * y; var dy = window.innerHeight * y;
window.scrollBy(dx, dy); window.scrollBy(dx, dy);
}; };
funcs.pos = function() { funcs.pos = function() {
var elem = document.documentElement; var elem = document.documentElement;
var dx = elem.scrollWidth - elem.clientWidth; var dx = elem.scrollWidth - window.innerWidth;
var dy = elem.scrollHeight - elem.clientHeight; var dy = elem.scrollHeight - window.innerHeight;
var perc_x, perc_y; var perc_x, perc_y;
if (dx === 0) { if (dx === 0) {