javascript - Jquery slider previous and next weird on double click -
i creating simple accordion using jquery, far looks acts weird on double click or if clicked more twice. instead of closing starts opening , closing depending how many times been clicked. thought implementing variable, if(!hasbeenclicked) not sure if work. wonder how prevent double clicks if clicked again on same option, close itself.`sliderclass : "scrollable", prevbutton : 'previous', nextbutton : 'next', duration : 5000, slidecount : 3, prevtext : 'previous', nexttext : 'next', 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 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(document).ready(function($) {
customslider.init();
});`
i added boolean property customslider object called sliding
. gets set true/false based on whether or not slider sliding, preventing double/triple-click slides.
i hope helps you!
Comments
Post a Comment