Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/85.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何生成一个";onNOmousemove“;带有JQuery的事件_Javascript_Jquery_Prototype_Jquery Events - Fatal编程技术网

Javascript 如何生成一个";onNOmousemove“;带有JQuery的事件

Javascript 如何生成一个";onNOmousemove“;带有JQuery的事件,javascript,jquery,prototype,jquery-events,Javascript,Jquery,Prototype,Jquery Events,我使用了一个可以使用jQuery的Web设计。现在有一点我需要相反的事件监视,因此我已经通过jQuery例程实现了这一点,该例程安装了一个“onnomousemove”事件。是的,您读取的是正确的,未发生事件 (下面)您可以在jQuery中找到我的allready工作解决方案。其思想是控制不发生的事件,并通过这个额外的指定 呵呵,我知道用这个来处理“onnoerror”事件是最愚蠢的。但这不是我们想要的。它现在起作用了,我想在这里向前迈进一步。那么我的问题是什么 问题来了:如何使用本机Javas

我使用了一个可以使用jQuery的Web设计。现在有一点我需要相反的事件监视,因此我已经通过jQuery例程实现了这一点,该例程安装了一个
“onnomousemove”
事件。是的,您读取的是正确的,
未发生事件

(下面)您可以在jQuery中找到我的allready工作解决方案。
其思想是控制不发生的事件,并通过这个额外的指定

呵呵,我知道用这个来处理
“onnoerror”
事件是最愚蠢的。但这不是我们想要的。它现在起作用了,我想在这里向前迈进一步。那么我的问题是什么

问题来了:如何使用
本机Javascript EventListening启动相同的行为
so
元素。addEventListener(…)也可以处理相同的事件吗

问题:像Chrome这样较新的Web浏览器,Firefox已经实现了一个
CustomEvent
处理来实现这一点,但在较旧的浏览器中,应该有一种使用prototype的方法。 我现在对jQuery有点盲目,不管怎样,有没有人知道用传统方式生成自定义事件的奇怪技巧,而不使用prototype.js或其他库?即使是使用jQuery的解决方案也可以,但理想的目标是本机侦听器应该能够处理它

jQuery:

(function($){
    $.fn.extend({
        // extends jQuery with the opposite Event Listener
        onno:function(eventname,t,fn){
            var onnotimer = null;
            var jqueryevent = {};
            $(this).on( eventname, function(e){
                window.clearTimeout(onnotimer);
                function OnNoEventFn(){
                    jqueryevent = jQuery.Event( "onno"+eventname );
                    $(this).trigger(jqueryevent);
                    e.timeStampVision=e.timeStamp+t;
                    e.timer=t; e.type="onno"+eventname;
                    fn(e);
                }
                onnotimer = window.setTimeout( OnNoEventFn, t);
            });
            return $(this);
        }
    });
})(jQuery);

$(document).ready(function() {
    // installs "onnomousemove" and fires after 5sec if mousemove does not happen.
    $(window).onno('mousemove', 5000, function(e){
        console.log('function fires after:'+e.timer+'ms at:'+e.timeStampVision+'ms with:"'+e.type+'" event, exact fired:', e.timeStamp);
    });
    // installs "onnoclick" and fires after 4sec if click does not happen.
    $(window).onno('click', 4000, function(e){
        console.log('function fires after:'+e.timer+'ms at:'+e.timeStampVision+'ms with:"'+e.type+'" event, exact fired:', e.timeStamp);
    });
    
    // just for demonstration, routine with "onno.." eventnamescheme
    $(window).on('onnomousemove',function(e){
        console.log( 'tadaaaa: "'+e.type+'" works! with jQuery Event',e);
    });
    // same for "onnoclick"
    $(window).on('onnoclick',function(e){
        console.log( 'tadaaaa: "'+e.type+'" works! with jQuery Event',e);
    });
});

// but how to install Custom Events even in older Safari ?
// newer Chrome, Firefox & Opera have CustomEvent.
window.addEventListener('onnomousemove',function(e){
    console.log('native js is watching you',e);
},false);

如果使用
CustomEvent()
对于您想要支持的浏览器来说太新,那么过时的方法是…谢谢,现在就试试。在那之前,玩点什么很好,很好的提示。现在我还认识到touchpad双指滚动(不产生mousemove)正在mousemove上触发事件,对吗?哎呀!啊!不,没有错,mousemove被激发是因为它开始滚动页面,这是相对mousemove到page offsetY的。