我是個白癡,所以在這裏...如何停止導航按鈕被按下直到動畫完成?
問題: 我使用幻燈片類型導航系統來查看產品。一切都很好,直到在動畫完成之前多次點擊下一個/前一個箭頭。點擊它不止一次會導致事情完全漏洞,並通過地獄將div發送到不可逆轉的水平螺旋。我想知道是否有辦法阻止用戶多次點擊下一個/上一個箭頭,以便幻燈片導航不會出錯。
代碼:
var SlideWidth = 305;
var SlideSpeed = 1000;
$(document).ready(function() {
// set the prev and next buttons display
SetNavigationDisplay();
});
function CurrentMargin() {
// get current margin of slider
var currentMargin = $("#slider-wrapper").css("margin-left");
// first page load, margin will be auto, we need to change this to 0
if (currentMargin == "auto") {
currentMargin = 0;
}
// return the current margin to the function as an integer
return parseInt(currentMargin);
}
function SetNavigationDisplay() {
// get current margin
var currentMargin = CurrentMargin();
// if current margin is at 0, then we are at the beginning, hide previous
if (currentMargin == 0) {
$("#PreviousButton").hide();
}
else {
$("#PreviousButton").show();
}
// get wrapper width
var wrapperWidth = $("#slider-wrapper").width();
// turn current margin into postive number and calculate if we are at last slide, if so, hide next button
if ((currentMargin * -1) == (wrapperWidth - SlideWidth)) {
$("#NextButton").hide();
}
else {
$("#NextButton").show();
}
}
function NextSlide() {
// get the current margin and subtract the slide width
var newMargin = CurrentMargin() - SlideWidth;
// slide the wrapper to the left to show the next panel at the set speed. Then set the nav display on completion of animation.
$("#slider-wrapper").animate({ marginLeft: newMargin }, SlideSpeed, 'easeInOutElastic', function() { SetNavigationDisplay() });
}
function PreviousSlide() {
// get the current margin and subtract the slide width
var newMargin = CurrentMargin() + SlideWidth;
// slide the wrapper to the right to show the previous panel at the set speed. Then set the nav display on completion of animation.
$("#slider-wrapper").animate({ marginLeft: newMargin }, SlideSpeed, 'easeOutElastic', function() { SetNavigationDisplay() });
}
和導航鍵:
<a href="javascript:void(0)" onclick="PreviousSlide()" id="PreviousButton" style="padding-right:40px;"><img src="IMGS/arrow2.png"></a><a href="javascript:void(0)" onclick="NextSlide()" id="NextButton" style="padding-right:40px;"><img src="IMGS/arrow.png"></a>
從我任何幫助=性崇拜。
謝謝!
我的天啊。你是個天才。像魅力一樣工作!一直堅持了兩天!所有的雹子mVChr !!!! –