Удалось ли кому-нибудь создать собственный курсор для мобильных устройств, который следует за вашим пальцем при касании экрана с помощью JS?
У меня есть простой пример кода для создания курсора:
Код: Выделить всё
// Cursor logic
const cursor = document.getElementById('cursor');
let isTouching = false;
const updateCursorPosition = (x, y) => {
// translate3d + position
cursor.style.transform = `translate3d(${x}px, ${y}px, 0)`;
};
document.addEventListener('touchstart', (e) => {
isTouching = true;
const touch = e.touches[0];
updateCursorPosition(touch.clientX, touch.clientY);
cursor.style.opacity = '1';
}, { passive: true });
document.addEventListener('touchmove', (e) => {
if (!isTouching) return;
const touch = e.touches[0];
updateCursorPosition(touch.clientX, touch.clientY);
}, { passive: true });
document.addEventListener('touchend', () => {
isTouching = false;
cursor.style.opacity = '0';
});
Подробнее здесь: https://stackoverflow.com/questions/798 ... e-using-js
Мобильная версия