Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的代码:
<div id="myDiv"> Hello </div>
#myDiv { width:200px; height:100px; background-color:red; }
$("#myDiv").mousemove(function (e) { console.log($(this).offset().left); });
它总是说“0”。我哪里错了?</p>
试试这个。
console.log("X Axis : " + e.pageX + " Y Axis : " + e.pageY);
这对我有用:-)
$(this).offset()产生 的位置,而#myDiv不是鼠标光标的位置。使用e.clientX.
$(this).offset()
#myDiv
e.clientX