-1

我有一些DIV通过单击另一个 DIV 触发元素淡入。我想不出一个脚本来:

  • 鼠标离开然后点击外部-淡出DIV

感谢您的任何建议。

4

1 回答 1

1

如果我理解正确,这就是你想要的:

$(document).ready(function(){

  var button = $("#div1");
  var container = $("#div2");    

  button.on('click', function(){

       container.fadeIn();

  });      

  $(document).mouseup(function (e){

        // check if click target is element or one of its children
        if (!container.is(e.target) && container.find(e.target).length == 0){

            container.fadeOut();

        }
  });

});

这是小提琴:http: //jsfiddle.net/neQuK/

于 2012-12-06T10:22:25.417 回答