[Glitch] Center thumbnails on focus point

Port the display part of the following commits to glitch-soc:
* 90f12f2e5a
* b170627ceb
* 11697d6894
* 56eb5c3f34
This commit is contained in:
Thibaut Girka
2018-04-14 20:31:47 +02:00
parent f1e25b672a
commit dcc1c10937
2 changed files with 21 additions and 9 deletions

View File

@@ -29,7 +29,7 @@ const formatTime = secondsNum => {
return (hours === '00' ? '' : `${hours}:`) + `${minutes}:${seconds}`;
};
const findElementPosition = el => {
export const findElementPosition = el => {
let box;
if (el.getBoundingClientRect && el.parentNode) {
@@ -60,7 +60,7 @@ const findElementPosition = el => {
};
};
const getPointerPosition = (el, event) => {
export const getPointerPosition = (el, event) => {
const position = {};
const box = findElementPosition(el);
const boxW = el.offsetWidth;
@@ -76,7 +76,7 @@ const getPointerPosition = (el, event) => {
pageY = event.changedTouches[0].pageY;
}
position.y = Math.max(0, Math.min(1, ((boxY - pageY) + boxH) / boxH));
position.y = Math.max(0, Math.min(1, (pageY - boxY) / boxH));
position.x = Math.max(0, Math.min(1, (pageX - boxX) / boxW));
return position;