windowAddMouseWheel()
function windowAddMouseWheel() {
var scrollFunc = function (e) {
e = e || window.event
if (e.wheelDelta) { //判断浏览器IE,谷歌滑轮事件
if (e.wheelDelta >0) { //当滑轮向上滚动时
alert("滑轮向上滚动")
}
if (e.wheelDelta <0) { //当滑轮向下滚动时
alert("滑轮向下滚动")
}
} else if (e.detail) { //Firefox滑轮事件
if (e.detail>0) { //当滑轮向上滚动时
alert("滑轮向上滚动")
}
if (e.detail<0) { //当滑轮向下滚动时
alert("滑轮向下滚动")
}
}
}
//给页面绑定滑轮滚动事件
if (document.addEventListener) {
document.addEventListener('DOMMouseScroll', scrollFunc, false)
}
//滚动滑轮触发scrollFunc方法
window.onmousewheel = document.onmousewheel = scrollFunc
}
没用C写过,要用C++.当 消息 WM_MOUSEWHEEL 发生时,滚轮转动。
LRESULT CALLBACK WindowProc(
HWND hwnd, // handle to window
UINT uMsg, // WM_MOUSEWHEEL
WPARAM wParam, // key indicator and wheel rotation
LPARAM lParam// horizontal and vertical position
)
鼠标光标位置 是 x,y .
滚轮位置 实际上是 z. 顺时针还是逆时针 从转动前后位置判断。
zDelta = GET_WHEEL_DELTA_WPARAM(wParam) // 滚轮转动值
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)