开发者

Make a jQuery element slide up if clicked anywhere outside of it

I have a drop down that I want to slideup when clicked anywhere outside of it (and all it's child elements)

My code seems to not be working :(

$(docum开发者_如何学JAVAent).ready(function () {
  $('*').not(".drop").click(function() {
    $('.drop').slideUp('medium', function() {
// Animation complete.
});});});


Try this I hope this will help you.

$(document).ready(function () {
  $('.drop').click(function(e){
     e.stopPropagation();
  });
  $('html').click(function() {
    var $drop = $('.drop');
    if($drop.is(":visible")) {
      $drop.slideUp('medium', function() {
        // Animation complete.
      });
    }
  });
 });


$(document).click(function() {
    if ($('.drop').is(':visible'))
        $('.drop').slideUp();
});

$(".drop").click(function() {
    $('.drop').slideDown();
    return false;
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜