1、jquery中event.originalEvent属性
该方法的作用是指向原始的事件对象
2、JS滚轮事件(mousewheel/DOMMouseScroll)
IE、Chrome:mousewheel
FireFox:DOMMouseScroll
IE、Chrome:event.wheelDelta(向下滚动为负值)
FireFox:event.detail(向下滚动为正值)
$(document).bind({ // Mouse Scroll // IE、Chrome:mousewheel // FireFox:DOMMouseScroll 'mousewheel DOMMouseScroll' : function(e) { var delta = e.originalEvent.wheelDelta || - e.originalEvent.detail, time = new Date().getTime(); if(time - scroll_screen.lastTime < 1000) { return; } scroll_screen.move(delta); //if( delta < 0 ){ // next scroll_screen.lastTime = time; } });
3、jquery右键事件
contextmenu
4、监听输入框(input、textarea)常用事件
keyup
keydown e.keyCode == 13
blur
propertychange(鼠标粘贴)
input(鼠标粘贴)
5、js监听横屏(android上只能在window绑定横屏事件,否则不起效果)
var orientationchangeHandler = function () { setTimeout(function () { // do something }, 100); }; window.addEventListener('orientationchange', orientationchangeHandler); window.removeEventListener('orientationchange', orientationchangeHandler);
6、监听手机摇动
//监听手机摇动事件 if (window.DeviceMotionEvent) { window.addEventListener('devicemotion', deviceMotionHandler, false); } else { alert('你的设备不支持DeviceMotion事件'); } var SHAKE_THRESHOLD = 3000; // ios:3000,android:600?800? var last_update = 0; var x = y = z = last_x = last_y = last_z = 0; function deviceMotionHandler(eventData) { var acceleration = eventData.accelerationIncludingGravity; var curTime = new Date().getTime(); //100ms监听一次,拒绝重复监听 if ((curTime - last_update) > 100) { var diffTime = curTime - last_update; last_update = curTime; x = acceleration.x; y = acceleration.y; z = acceleration.z; var speed = Math.abs(x + y + z - last_x - last_y - last_z) / diffTime * 10000; if (speed > SHAKE_THRESHOLD) { // shake success } last_x = x; last_y = y; last_z = z; } }