我正在使用 jQuery 创建一个简单的手风琴,到目前为止它看起来不错,但它在双击时表现得很奇怪,或者即使单击了两次以上。它不仅仅是关闭自身,而是根据点击次数开始打开和关闭。考虑过实现一个变量,比如 if(!hasbeenclicked) 但不确定这是否可行。所以基本上我想知道如何防止它双击如果再次单击同一选项,只需关闭自身。`sliderClass:“scrollable”,prevbutton:'previous',nextbutton:'next',持续时间:5000,slideCount:3 , prevText : '上一个', nextText : '下一个', clickTiming : 5000,
initSlider : function(sliderObject, direction, eventType) {
slideCount = this.slideCount;
slideWidth = sliderObject.find('li:first-child').outerWidth(true);
var lefVal = slideWidth * slideCount;
if (direction == 'moveLeft')
lefVal = -lefVal;
if (sliderObject.attr("class").indexOf("autoScroll") >= 0) {
var all_classes = sliderObject.attr("class");
if (all_classes.length > 1) {
var auto_scroll_time = all_classes.match(/\d+/)[0];
auto_scroll_time = parseInt(auto_scroll_time.split("autoScroll").join(""));
interval_duration = auto_scroll_time * this.duration;
}
}
function slideAnimate() {
if (eventType == 1)
var animateTime = this.duration;
else
var animateTime = this.duration;
sliderObject.animate({
left : lefVal
}, this.duration, function() {
var counter = 0;
sliderObject.children().each(function() {
if (counter < slideCount) {
$(this).appendTo(sliderObject);
}
counter++;
});
sliderObject.css('left', '');
});
}
if (eventType == 1) {
setInterval(function() {
slideAnimate()
}, interval_duration);
} else
slideAnimate();
// When called from normal click
},
init : function() {
$('.' + this.prevbutton).live('click', function() {
customSlider.initSlider($(this).prev(), 'moveRight', 2);
$(this).unbind("click");
});
/**
*Intialize next click
*/
$('.' + this.nextbutton).live('click', function() {
customSlider.initSlider($(this).prev().prev(), 'moveLeft', 2);
});
$('.' + this.sliderClass).each(function() {
customSlider.initSlider($(this), 'moveLeft', 1);
})
}
};
jQuery(文档).ready(函数($) {
customSlider.init();
});`