Wednesday, 15 January 2014

jquery - How can I calculate mouse specific movement with JavaScript -



jquery - How can I calculate mouse specific movement with JavaScript -

i want know how can calculate mouse specific movement.

i want have advices how determine mouse moved b.

for example, win8. when mouse on side of window, drop down, sidebar appear.

$(window).on('mousemove' function(e){ if(e.pagex on area of or close side of window){ // how can calculate if mouse y point point?? if(y moved b){ //do } } })

you can determine left hand side of window checking width:

if(e.pagex >= ($(window).width() - 20))

will check if mouse within 20px of right-hand side of window.

to check how far it's moved, you'll need record lastly known position somehow, , compare it. illustration might this:

var last_pos = { x: false, y: false }, coord_check = $(window).width() - 20; // or whatever value right want check. $(window).on('mousemove' function(e) { if(e.pagex >= coord_check) { // if they're null, can't anything: if((last_pos.x !== false && last_pos.y !== false) && ((e.pagex - last_pos.x) > 20)) { // can access current position through e.pagex , e.pagey // last_post.x , last_pos.y tell lastly known position } } // need update lastly position: last_pos.x = e.pagex; last_pos.y = e.pagey; });

javascript jquery events mouse

No comments:

Post a Comment