FadeIn Div at Mouse Cursor on Keypress [Javascript/JQuery] -
i'm trying make dynamic javascript menu (contained in div) appear @ visitor's mouse coordinates when press ctrl+m
on keyboard (m signifying menu, , ctrl+m
not being bound in browsers far i'm aware). way, wherever on site , wherever mouse is, can pull menu pressing combination , return wherever wish go. @ same time, having menu not shown until press key allows me control design experience without having worry nav menu.
i've pulled 2 different pieces of code found on here in attempt myself, i'm running unexpected issue.
- i'm not sure how denote
ctrl+m
key combination in event handler. - i'm getting couple of errors on code checker i'm not sure how fix myself.
- i'm not sure how make menu appears on ctrl+m, , stays there until
ctrl+m
pressed again (a toggle switch).
i'm still learning how javascript works.
here's link progress i've made far: http://jsfiddle.net/nrz4z/
in example, you're binding mousemove
handler inside keypress
handler. need them separately:
var mousex; var mousey; $(document).ready(function () { $(document).mousemove(function (e) { mousex = e.pagex; mousey = e.pagey; }); $(document).keypress(function (event) { if (event.which == 109) { $('#examples').css({ 'top': mousey, 'left': mousex }).fadein('slow'); }; }); });
that should allow position @ show menu.
Comments
Post a Comment