js如何监听手指在屏幕某个位置停留了1s 当停留1s执行某个函数

JavaScript020

js如何监听手指在屏幕某个位置停留了1s 当停留1s执行某个函数,第1张

var test

$("#div").mouseenter(function() {

test= setTimeout(function() {

Alert("1")

}, 1000)

}).mouseleave(function() {

clearTimeout(test)

})

监听方法在js中的实现如下:function addEventListener(string eventFlag, function eventFunc, [bool useCapture=false])eventFlag : 事件名称,如click、mouseover…eventFunc: 绑定到事件中执行的动作useCapture: 指定是否绑定在捕获阶段,true为是,false为否,默认为true在事件监听流中可以使用event.stopPropagation()来阻止事件继续往下流IE中使用自有的attachEvent函数绑定时间,函数定义如下:function attachEvent(string eventFlag, function eventFunc)eventFlag: 事件名称,但要加上on,如onclick、onmouseover…eventFunc: 绑定到事件中执行的动作在事件监听流中可以使用window.event.cacenlBubble=false来阻止事件继续往下流总结:addEventListener(string eventFlag, function eventFunc, [bool useCapture=false]),针对ff,chrome,safari浏览器,false指冒泡阶段,默认为true,指捕获阶段。不过一般我们都用false。 attachEvent(string eventFlag, function eventFunc),针对ie系列、还有opera浏览器,少了事件处理机制的参数,只指定事件类型(别忘了on)和触发哪个函数。