Код: Выделить всё
const cursorTypes = ["default", "pointer", "text", "move", "help", "progress", "crosshair", "not-allowed", "zoom-in", "zoom-out", "grab", "grabbing"];
let cIndex = 0;
setInterval(() => {
console.log(cIndex);
document.body.style.cursor = cursorTypes[cIndex];
cIndex++;
if (cIndex >= cursorTypes.length) {
cIndex = 0;
}
}, 500);
Я пробовал использовать функцию requestAnimationFrame для обновления анимации:
Код: Выделить всё
let frameIndex = 0;
let step = (timestamp, elapsed) => {
if (elapsed > 1000 / frameRate) {
document.body.style.cursor = cursorTypes[cIndex];
frameIndex++;
if (frameIndex >= frameURLs.length) {
frameIndex = 0;
}
elapsed = 0;
}
console.log(frameIndex);
window.requestAnimationFrame((_timestamp) =>
step(_timestamp, elapsed + _timestamp - timestamp)
);
};
window.requestAnimationFrame((timestamp) => step(timestamp, 0));
Код: Выделить всё
@keyframes cursor-animation-keyframes{
0% { cursor: default; }
6% { cursor: pointer; }
...
}
.cursor-animation {
animation: cursor-animation-keyframes 1866ms step-end infinite;
}
Что мне следует сделать, чтобы модификация стиля курсора мыши по-прежнему работала после того, как браузер теряет фокус?
Подробнее здесь: https://stackoverflow.com/questions/793 ... fter-the-b
Мобильная версия