JQuery实现鼠标检测 左右移动

2025-12-16 05:00:14
推荐回答(1个)
回答1:

给你写了个简单的Demo,需要你自己替换JQuery.js,代码如下:





无标题文档


html,body {
height: 100%;
text-align: center;
}

#dirSpan {
font-size: 80px;
font-weight: 900;
color: #4488CD;
}


$(document).ready(function() {
var lastX = 0;
$("body").mousemove(function(e) {
if (lastX > e.pageX) {
$("#dirSpan").text("←");
} else if (lastX < e.pageX) {
$("#dirSpan").text("→");
} else {
$("#dirSpan").text("—");
}
lastX = e.pageX;
});
});