javascript - Chaining multiple Jquery events with OR operator -
i'm creating panel slides down when user focuses search box. i'm terrible @ jquery still learning, i've managed create basic functionality:
$(document).ready(function() { $(".search-panel").hide(); $("#search_form [type='text']") .focus(function() { $(".search-panel").slidedown("fast"); }) .focusout(function() { $(".search-panel").slideup("fast"); }); }); with basic functionality clicking outside text box fold panel i'm trying implement complex set of conditions whereby:
if (textbox.focus) { show search panel} if (texbox.losefocus) && ( not search-panel.mouseover) && ( not (anything-in-search-panel-is-focused) ) basically need make sure user not hovering on or interacting panel in way , textbox not focused before slide up.
jsfiddle of current situation: http://jsfiddle.net/b9g9d6gf/
instead of using .focusout() function, should bind click function on document.
$(document).ready(function () { $(".search-panel").hide(); $("#search_form [type='text']") .focus(function () { $(".search-panel").slidedown("fast"); }); $(document).click(function(e) { if( !( $(e.target).is('#search_form *')) ){ $(".search-panel").slideup("fast"); } }); }); if document clicked, anywhere, looks if target isn't element inside #search_form. if not, slide .search-panel.
note:
removed label , changed span labels. clicking label (un)check checkbox inside it. having 3 checkboxes making act wrong. either make 3 separate labels (instead of span) or remove it.
Comments
Post a Comment