javascript - Interface menu, close if opened and user clicks outside menu -
i'm trying improve interface of menu here:
http://jsfiddle.net/u5brv/2/
i think it's great toggled on click think if user clicks anywhere else, example, bottom corner of screen, menu should toggle close if isn't already.
$(document).ready(function () { $('#nav li').mousedown(function () { $('ul #items').toggle(100); }); }); how 1 apporach in efficient way possible. if menu open need track every mouse click , see if on menu or not?
any help appreciated.
james
you need attach click handler document closes menu:
$('#nav li').click(function (e) { e.stoppropagation(); $('ul #items').toggle(100); }); $(document).click(function() { $('#items').hide(); }); note stoppropagation required on opening link stop event reaching document itself.
javascript jquery
No comments:
Post a Comment