mirror of
https://github.com/SoPat712/videospeed.git
synced 2025-10-30 02:30:35 -04:00
fix and simplify drag position calculation
This commit is contained in:
14
inject.js
14
inject.js
@@ -311,21 +311,15 @@ chrome.extension.sendMessage({}, function(response) {
|
|||||||
|
|
||||||
function handleDrag(video, controller) {
|
function handleDrag(video, controller) {
|
||||||
const parentElement = controller.parentElement,
|
const parentElement = controller.parentElement,
|
||||||
boundRect = parentElement.getBoundingClientRect(),
|
shadowController = controller.shadowRoot.querySelector('#controller');
|
||||||
shadowController = controller.shadowRoot.querySelector('#controller'),
|
|
||||||
drag = shadowController.querySelector('.draggable'),
|
|
||||||
offsetLeft = boundRect.left + drag.offsetLeft + drag.offsetWidth,
|
|
||||||
offsetTop = boundRect.top + drag.offsetTop + drag.offsetHeight;
|
|
||||||
|
|
||||||
video.classList.add('vcs-dragging');
|
video.classList.add('vcs-dragging');
|
||||||
shadowController.classList.add('dragging');
|
shadowController.classList.add('dragging');
|
||||||
|
|
||||||
const startDragging = (e) => {
|
const startDragging = (e) => {
|
||||||
let newLeft = Math.max(0, e.clientX - offsetLeft);
|
let style = shadowController.style;
|
||||||
let newTop = Math.max(0, e.clientY - offsetTop);
|
style.left = parseInt(style.left) + e.movementX + 'px';
|
||||||
|
style.top = parseInt(style.top) + e.movementY + 'px';
|
||||||
shadowController.style.left = newLeft + 'px';
|
|
||||||
shadowController.style.top = newTop + 'px';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const stopDragging = () => {
|
const stopDragging = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user