[英]$('html').click event after another click event
Intention: 意向:
Issue: While DIV is in the slideDown position, (var isclicked = true), on click of $('html') keeps firing. 问题:当DIV处于slideDown位置时(var isclicked = true),点击$('html')会一直触发。 What am I missing so that on click of $('html') only fires WHILE DIV is (var isclicked = true) 我错过了什么,所以点击$('html')只会触发WHILE DIV(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/ JSFiddle: http : //jsfiddle.net/7Zfwx/92/
Remember to stop (and complete) the previous animation first: 请记住先停止(并完成)上一个动画:
if(isclicked == false){
$('#myslider').stop(true, true).slideDown('slow');
isclicked = true;
}else{
$('#myslider').stop(true, true).slideUp('slow');
isclicked = false;
}
Demo: http://jsfiddle.net/maniator/7Zfwx/94/ 演示: http : //jsfiddle.net/maniator/7Zfwx/94/
Ditch the global isClicked
var, and just use a slideToggle
: isClicked
全局的isClicked
var,只需使用slideToggle
:
$("#clickme").click(function(e) {
e.stopPropagation();
$("#myslider").slideToggle("slow");
});
$("body").click(function() {
$("#myslider").is(":visible") ? $("#myslider").slideUp("slow") : 0
});
Demo: http://jsfiddle.net/7Zfwx/103/ 演示: http : //jsfiddle.net/7Zfwx/103/
use $('body')
instead of $('html')
使用$('body')
而不是$('html')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.