Attach a mousemove
handler to the document, where you update the (absolute) position of diClock
element to reflect the mouse coordinates you get from the event. The position update part and the time update part are separate; you do not need to change your showTime
function.
Time which follows the mouse
-
04-10-2022 - |
سؤال
I just wrote a simple javascript which displays the time. So i asked myself if is it possible to display the time always over the mouse. I simply don´t know how to do it, I need your help.
Here is the JS Code
function showTime() {
var currentTime = new Date(); var h = currentTime.getHours(); var m = currentTime.getMinutes(); var s = currentTime.getSeconds(); var myClock = document.getElementById('diClock'); myClock.textContent = h + ':' + m + ':' + s; requestAnimationFrame(showTime); }
showTime();
المحلول
لا تنتمي إلى StackOverflow