在jQuery开发环境下:
1.滚轮事件:(需要监听mousewheel DOMMouseScroll)
//代码 只是我拷贝的 代码片段$(document).on("mousewheel DOMMouseScroll", function(e)
{
console.log('mousewheel');
if(_this.switch)
{
_this.switch = false;
var delta = (e.originalEvent.wheelDelta && (e.originalEvent.wheelDelta > 0 ? 1 : -1)) ||
(e.originalEvent.detail && (e.originalEvent.detail > 0 ? -1 : 1));
if(delta > 0)
{
_this.index = _this.index - 1;
_this.index = Math.max(_this.index, 0);
_this._move(_this.index)
}
else if(delta < 0)
{
_this.index = _this.index + 1;
_this.index = Math.min(_this.index, _this.listLength - 1);
_this._move(_this.index);
}
}
});
2.PC鼠标滑动(我的业务需求只是需要判断鼠标按下和抬起 Y坐标变化 mousedown mouseup)
//代码 只是我拷贝的 代码片段$(document).stop().on("mousedown", function(e)
{
dowmY = e.screenY;
return false;
console.log('mousedowm' + 'x坐标' + e.screenX + ":" + 'y坐标' + e.screenY);
});
$(document).stop().on("mouseup", function(e)
{
if(_this.switch)
{
_this.switch = false;
console.log('mouseUP' + 'x坐标' + e.screenX + ":" + 'y坐标' + e.screenY);
if(e.screenY > dowmY)
{
_this.index = _this.index - 1;
_this.index = Math.max(_this.index, 0);
_this._move(_this.index)
}
else if(e.screenY < dowmY)
{
_this.index = _this.index + 1;
_this.index = Math.min(_this.index, _this.listLength - 1);
_this._move(_this.index);
}
return false;
}
});
3.移动端滑动事件(touchstart 和 touchend)
$(document).on('touchstart', function (event){
event.preventDefault();
console.log(event.originalEvent)
console.log('mobile' + event.originalEvent.targetTouches[0].pageY)
});
$(document).on('touchmove', function (event)
{
});
备注:
originalEvent:指向原始的事件对象。jquery 中操作时使用!
changedTouches :涉及当前事件的手指的一个列表。changedTouches[0]是列表中的第一个手指