Last active
January 4, 2018 04:04
-
-
Save rqreyes/d7334f3e37b7285d9ec5486da18910d9 to your computer and use it in GitHub Desktop.
when clicking outside, hide searchbox
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.search-trigger').click(function () { | |
$(this).toggleClass('active'); | |
$("#searchbox").toggle(); | |
$("#searchbox input").focus(); | |
}); | |
if (window.matchMedia("(min-width: 48em)").matches) { | |
var exclude_div = $("#searchbox, #searchbox *"); | |
$(document).click(function (e) { | |
if (!(exclude_div.is(e.target)) && !($(e.target).hasClass('search-trigger'))) { | |
$('.search-trigger').removeClass('active'); | |
$("#searchbox").hide(); | |
} | |
}); | |
} | |
$(window).resize(function () { | |
if ($(window).width() < 751) { | |
$("#searchbox").show(); | |
$(document).click(function (e) { | |
$("#searchbox").show(); | |
}); | |
} else { | |
$("#searchbox").hide(); | |
var exclude_div = $("#searchbox, #searchbox *"); | |
$(document).click(function (e) { | |
if (!(exclude_div.is(e.target)) && !($(e.target).hasClass('search-trigger'))) { | |
$('.search-trigger').removeClass('active'); | |
$("#searchbox").hide(); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment