[英]javascript or jquery : mouse events
Need your help in understanding this code..Is this Javascript ( expression language ) or JQuery. 在理解此代码时需要您的帮助。这是Javascript(表达语言)还是JQuery。 I tried to understand but didn't get it.
我试着去理解,但是没有理解。
var interval = 0, changed = false;
...............
...............
var start = function () {
$(document).on('mousedown mousemove scroll touchstart touchmove keydown', change);
setInterval(check, 1000);
};
var change = function () {
changed = true;
};
var check = function () {
console.log("changed .....");
};
start();
Basically I want to do something ( business logic ) if user had performed some events on browser.Got this code on net and felt like something this is doing the same what i want. 基本上,如果用户在浏览器上执行了一些事件,我想做一些事情(业务逻辑)。将这段代码放在网上,感觉就像在做我想要的事情。
var start = function () {
$(document).on('mousedown mousemove scroll touchstart touchmove keydown', change);
setInterval(check, 1000);
};
$(document)
refers to your entire HTML
document. $(document)
指整个HTML
文档。 ON will attach an event handler function for one or more events to the selected elements. ON将为一个或多个事件将事件处理程序功能附加到所选元素。 In your example , it'll attach the
mousedown mousemove scroll touchstart touchmove keydown
events to the document
. 在您的例子中,它会将
mousedown mousemove scroll touchstart touchmove keydown
事件附加到document
。 Once any of those events occur , the change
method gets called. 一旦发生任何这些事件,就会调用
change
方法。
setInterval is used to call a method repeatedly for the given duration.In your Example , it calls the check
method every 1000ms or 1 second setInterval用于在给定持续时间内重复调用方法。在您的示例中,它每1000毫秒或1秒调用一次
check
方法
This following part is jQuery specific, all other are pure JavaScript. 以下部分是jQuery特有的,所有其他都是纯JavaScript。
$(document).on('mousedown mousemove scroll touchstart touchmove keydown', change);
This is a event handler of jQuery which is calling a native javascript function change()
. 这是jQuery的事件处理程序,正在调用本地javascript函数
change()
。
Notes: 笔记:
To run the jQuery part you need to import jQuery Library from their site. 要运行jQuery部分,您需要从其站点导入jQuery库。
You can identify the jQuery selectors by user of $
infront. 您可以通过
$
infront的用户来标识jQuery选择器。 ( $
does not always means jQuery) (
$
并不总是表示jQuery)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.