意图:
- 单击 (#clickme) 时,DIV 会向下滑动并进入视图,并且 (var isclicked = true)
- 当 (var isclicked = true) 并单击 (#clickme) 时,DIV 向上滑动并且 (var isclicked = false)
- 当 (var isclicked = true) 并且 DIV 在视图中时,单击 $('html') 会向上滑动 DIV 并且 (var isclicked = false)
问题:当 DIV 处于 slideDown 位置时,(var isclicked = true),单击 $('html') 时会继续触发。我错过了什么,所以点击 $('html') 只会触发 WHILE DIV is (var isclicked = true)
var isclicked = false;
$('#clickme').click(function(event){
doslider();
console.log(isclicked);
if(isclicked == true){
$('html').click(function(event){
console.log('is box opened? '+isclicked);
});
}
});
function doslider(){
if(isclicked == false){
$('#myslider').slideDown('slow');
isclicked = true;
}else{
$('#myslider').slideUp('slow');
isclicked = false;
}
return isclicked; }
JSFiddle:http: //jsfiddle.net/7Zfwx/92/