feat: Change edge detection for HippieTaskBar
- Add position to options - New function for edge detection according to mouse position - set and use options.position
This commit is contained in:
parent
9696442a91
commit
7912b002a2
3 changed files with 29 additions and 13 deletions
|
|
@ -346,20 +346,37 @@ function checkButtonAndTarget(event, element, button = 0) {
|
|||
);
|
||||
}
|
||||
|
||||
function getClosestEdge(element) {
|
||||
function getClosestEdgeToElement(element) {
|
||||
'use strict';
|
||||
|
||||
const rect = element.getBoundingClientRect();
|
||||
const windowWidth = window.innerWidth;
|
||||
const windowHeight = window.innerHeight;
|
||||
const distances = {
|
||||
top: rect.top,
|
||||
right: windowWidth - rect.right,
|
||||
bottom: windowHeight - rect.bottom,
|
||||
right: window.innerWidth - rect.right,
|
||||
bottom: window.innerHeight - rect.bottom,
|
||||
left: rect.left
|
||||
};
|
||||
|
||||
return Object.keys(distances).reduce((a, b) => distances[a] < distances[b] ? a : b);
|
||||
}
|
||||
|
||||
function getClosestEdgeToMouse(event) {
|
||||
'use strict';
|
||||
|
||||
const mouseX = event.clientX;
|
||||
const mouseY = event.clientY;
|
||||
const distances = {
|
||||
left: mouseX,
|
||||
right: window.innerWidth - mouseX,
|
||||
top: mouseY,
|
||||
bottom: window.innerHeight - mouseY
|
||||
};
|
||||
|
||||
return Object.keys(distances).reduce((a, b) =>
|
||||
distances[a] < distances[b] ? a : b
|
||||
);
|
||||
}
|
||||
|
||||
function centerElementUnderCursor(event, element) {
|
||||
const offsetX = element.getBoundingClientRect().width / 2;
|
||||
const offsetY = element.getBoundingClientRect().height / 2;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue