@adoratorio/apollo
Version:
A JS library for custom cursor
46 lines • 1.4 kB
JavaScript
class CSSRender {
context = null;
options;
cursorBounding;
name = 'CSSRender';
constructor(options) {
const defaults = {
cursor: document.querySelector('.apollo__cursor'),
precision: 4,
render: true,
};
this.options = { ...defaults, ...options };
this.cursorBounding = this.cursorElement.getBoundingClientRect();
}
register(context) {
this.context = context;
}
frame() {
if (!this.context)
return;
if (!this.options.render)
return;
const position = {
x: parseFloat((this.context.coords.x - (this.cursorBounding.width / 2)).toFixed(this.options.precision)),
y: parseFloat((this.context.coords.y - (this.cursorBounding.height / 2)).toFixed(this.options.precision)),
};
if (this.cursorElement !== null) {
const transform = `translateX(${position.x}px) translateY(${position.y}px) translateZ(0px)`;
this.cursorElement.style.transform = transform;
}
}
startRender() {
this.options.render = true;
}
stopRender() {
this.options.render = false;
}
get cursorElement() {
return this.options.cursor;
}
get boundings() {
return this.cursorBounding;
}
}
export default CSSRender;
//# sourceMappingURL=index.js.map