[英]Having trouble with jquery if/else statement and 'slide' effect hiding last element
这是我自己拼凑的第一个jquery脚本。 我在尝试使if / else语句正常工作时遇到问题。 如果您单击的框/链接当前可见,我只是希望脚本不运行。
这是没有if语句的脚本: http : //jsfiddle.net/Vitruvius/yqMAN/
$('.link').click(function () {
var parentName = $(this).closest('ul').attr('id');
var boxNumber = $(this).attr('id');
$('.' + parentName).children('.active').toggle('slide',{direction:'right'},function(){
$('.' + parentName + ' ' + 'div').removeClass('active');
$('.' + parentName).children('.' + boxNumber).show().effect('slide').addClass('active');
});
});
这是我尝试的if语句: http : //jsfiddle.net/Vitruvius/h8CMU/
$('.link').click(function () {
var parentName = $(this).closest('ul').attr('id');
var boxNumber = $(this).attr('id');
if($('.' + parentName).children('.' + boxNumber).hasClass('active')){
return:false;
}
else {
$('.' + parentName).children('.active').toggle('slide',{direction:'right'},500,function(){
$('.' + parentName + ' ' + 'div').removeClass('active');
$('.' + parentName).children('.' + boxNumber).show().effect('slide').addClass('active');
});
}
});
另外,有人知道为什么滑动效果会在最后滑动消失之前隐藏最后一个元素吗? 我在任何地方都找不到答案。
如果您有任何提示和/或建议,请告诉我。 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.