简体   繁体   English

如何使用Javascript(jquery,dojo)制作新闻事件?

[英]How can i make press event with Javascript (jquery, dojo)?

In the touch screen. 在触摸屏中。

  • if i keep press in the center of a screen for 20 seconds, i want to show alert("This is a secret window"); 如果我按住屏幕中央20秒,我想显示警报(“这是一个秘密窗口”);

  • If i pressed for 5 seconds each corners in the touch screen as: top/left top/right bottom/right bottom/left it will show alert("This is more secret window"); 如果我按下触摸屏中的每个角落5秒钟:顶部/左上/右下/右下/左,它将显示警报(“这是更隐秘的窗口”);

How do i do this in jQuery/Dojo or Mootools or in plain Javascript? 我如何在jQuery / Dojo或Mootools或普通的Javascript中执行此操作? Any one ever did this? 有没有人这样做过? I do not find any "pressed" event with time set. 我没有找到任何时间设置的“按下”事件。

Note: there will be also many normal press inputs, so i want to do it in optimized way, for real-time actions except those two. 注意:还会有很多正常的印刷输入,所以我想以优化的方式进行,除了那两个以外的实时操作。

You need two event handlers and a timer. 您需要两个事件处理程序和一个计时器。

// Put this lot in a closure so you don't pollute the global namespace.
(function () {
    var timer;
    function onTouchStart() {
        timer = setTimeout(doTheThing, 20*1000);
    }
    function onTouchEnd() {
        clearTimeout(timer);
    }
    function doTheThing() {
        alert('foo')
    }
})();

Bind onTouchStart/End to the appropriate events on the appropriate elements. 将onTouchStart / End绑定到相应元素上的相应事件。

See a working example altered to operate with a mouse button and for 5 seconds (because 20 is too much time to hang around for this test). 查看一个更改为使用鼠标按钮操作的工作示例 ,持续5秒钟(因为此测试需要20个时间才能停留)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM