如何在Javascript/jQuery中获取鼠标移动事件的开始时间

How to get the starting time of a mousemove event in Javascript/jQuery?

本文关键字:事件 移动 开始 时间 开始时 鼠标 获取 Javascript jQuery      更新时间:2023-09-26

是否有任何与开始时间相关的属性可以从mousemove事件的回调函数中的"event"参数中获取?

您尝试过event.timeStamp吗?

返回事件发生的时间(自epoch以来以毫秒为单位)已创建。

当鼠标移动第一次发生在元素中时,此代码将存储时间(作为timestamp):

 var startTime = null;
    $('<YOUR_ELEMENT>').one('mousemove', function(e) {
        startTime = e.timeStamp;
        console.log(startTime);
    });