May 31, 2013

javascript or jquery : mouse events

VJS’s Question:

Need your help in understanding this code..Is this Javascript ( expression language ) or 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.

This following part is jQuery specific, all other are pure 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().

Notes:

  • To run the jQuery part you need to import jQuery Library from their site.

  • You can identify the jQuery selectors by user of $ infront. ($ does not always means jQuery)

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!