I wrote a JS panel class that shows a sliding panel on top, bottom, left or right border of the page.
The panel is shown when the mouse comes near to the top, bottom, left or right edge of the page (or by default).
The panel hides when the mouse leaves it.
Please see my CodePen: https://codepen.io/Samwise_71/pen/MWRVaJb
You will notice that sometimes when mouse leaves the panel, it can take some seconds until the hiding animation starts (tested in Firefox):
// Hide panel on mouse leave
this.#panel.on("mouseleave", function (e) { panel.hide(e); });
/**
* Slides the panel out of viewport.
* @param {event object} e
*/
hide(e) {
if (!this.isVisible()) {
return;
}
let ymax = this.#panel.height();
let xmax = this.#panel.width();
// Prevent leave to side of panels position
if (this.#position == UserInterface.Panel.PositionTop && e.offsetY < 0 ||
this.#position == UserInterface.Panel.PositionBottom && e.offsetY > ymax ||
this.#position == UserInterface.Panel.PositionLeft && e.offsetX < 0 ||
this.#position == UserInterface.Panel.PositionRight && e.offsetX > xmax) {
return;
}
let margin = this.getMargin();
let css = {};
css[margin.key] = -1 * margin.pixels;
let panel = this;
this.#panel.animate(css, this.#speed, function () { panel.isVisible(false); });
}
I'm not sure what causes this delay, it seems to be independent from mouse movement.
What should I change to start the animation immediately after mouse crosses panels border?