2013-11-24 2 views
0

@goddfree가 게시 한 내용을 잘못 읽었습니다. ,더블 클릭 방지 (onclick 없음)

$.when($('#carousel_ul_' + unique_id + ' li:last').clone().insertBefore('#carousel_ul_' + unique_id + ' li:first'), $('#carousel_ul_' + unique_id).css('left', '-=' + displace_width + 'px')).done($('#carousel_ul_' + unique_id + ':not(:animated)').animate({left: '+=' + scroll_width + 'px'}, 400, function(){$('#carousel_ul_' + unique_id + ' li:last').remove(); is_done = true; })); 

이 정말 우아한 해결책은 당신이

답변

0

을 @goddfree 감사 : 그의 해결책은 내가 참으로 다시의 isDone을 ​​설정하는 것은 그래서 같은 애니메이션 기능의 콜백에 배치되는 것을 만든 유일한 변화, 완벽하게 작동 HTML 앵커 태그에는 onClick 이벤트가 있습니다. 이런 식으로 해봤 니? 여기에서 발견 한 솔루션을 사용할 수 있어야합니다.

<a href="#" onclick='carousel("left", 99335)'><!--stuff here--></a> 

업데이트 :

내가이 당신을 위해 무엇을 찾고있는 것 같아요. 우리는 어떤 프로세스가 실행 중인지 여부를 확인하기 위해 isDone라는 변수를 추가

<a href="#" onclick='carousel("left", 99335)'>Button 1</a> 
<a href="#" onclick='carousel("right", 69235)'>Button 2</a> 
<a href="#" onclick='carousel("left", 91235)'>Button 3</a> 

: 당신은 세 개의 버튼이 있다고 (난 그냥 carousel 매개 변수를 만들고있어, 나는 그들이 무슨 뜻인지 단서가 없다). 모든 버튼이 같은 carousel 함수를 호출하기 때문에 isDone가 true로 설정되어있는 경우, 그들은 단지 실행됩니다,

//isDone is initially set to true, because nothing is running. 
var isDone = TRUE; 

function carousel(direction, unique_id) { 
//First of all, we can only execute the function is isDone is true. So we check for that: 
if(isDone) { 
//This implements the moment the function is called. We now know that it is currently in progress. 
isDone = FALSE; 
//This is the same as you had before 
if (direction == 'right') { 
    $(document).ready(function(){ 
     var displace_width = $('#carousel_ul_' + unique_id + ' li:last').outerWidth(true); 
     var scroll_width = $('#carousel_ul_' + unique_id + ' li:first').outerWidth(true); 
     //Here we set isDone equal to true when the .done is called: 
     $.when($('#carousel_ul_' + unique_id + ' li:last').clone().insertBefore('#carousel_ul_' + unique_id + ' li:first'), $('#carousel_ul_' + unique_id).css('left', '-=' + displace_width + 'px')).done(isDone = TRUE; $('#carousel_ul_' + unique_id + ':not(:animated)').animate({left: '+=' + scroll_width + 'px'}, 400, function(){$('#carousel_ul_' + unique_id + ' li:last').remove(); })); 
    }); 
} else { 
    $(document).ready(function(){ 
     var displace_width = $('#carousel_ul_' + unique_id + ' li:first').outerWidth(true); 
     var scroll_width = $('#carousel_ul_' + unique_id + ' li:nth-child(2n)').outerWidth(true); 
     //Same thing here 
     $.when($('#carousel_ul_' + unique_id + ' li:first').clone().insertAfter($('#carousel_ul_' + unique_id + ' li:last'))).done(isDone = TRUE; $('#carousel_ul_' + unique_id + ':not(:animated)').animate({left: '-=' + scroll_width + 'px'}, 400, function(){$('#carousel_ul_' + unique_id + ' li:first').remove(); $('#carousel_ul_' + unique_id).css('left', '+=' + displace_width + 'px'); })); 
    }); 
} 
} 
//If isDone is not true, then we tell the user that and don't execute anything: 
else { 
    alert("Not so fast! There is a process currently in progress."); 
} 
} 

이 방법 : 그래서 같은 carousel 함수를 수정 (I 주석을 사용하여 수정 사항을 설명). 그렇지 않으면 사용자에게 오류 경고가 표시되고 아무 것도 나타나지 않습니다.

+0

더 구체적으로 말하면, 각 링크에 고유 한 ID를 부여하면 사용할 수있는 솔루션을 찾을 수 있습니다. (예를 들어 다음 링크를 참조하십시오.) 모든 링크에 대해 PHP를 통해 ID를 생성하기 전에 누군가에게 더 나은 솔루션이 있는지 알고 싶었습니다.이 링크는 저에게 rube goldberg-y처럼 보입니다 (예 : http : /stackoverflow.com/questions/16715075/preventing-multiple-clicks-on-button) –

+0

문제를 완전히 이해하고 있지는 않지만 용서해주십시오. 게시 한 링크에서 제안 된 솔루션을 사용할 수 있습니까? 클릭 한 후 짧은 시간 동안 사용할 수 없습니까? – Charles

+0

내가 본 솔루션은 특정 호출 버튼이나 링크를 비활성화하여 작동합니다. 이 함수는 페이지 전체에서 수적으로 호출되기 때문에 호출하는 모든 링크를 비활성화 한 다음 일정 시간이 경과 한 후에 해당 링크를 다시 활성화하려면 약간의 인위적 작업이 필요합니다. 나는 그것이 실행 가능할지도 모른다고 생각하지만, 다른 누군가가 더 나은 해결책을 먼저 가지고 있는지를 알 수있을 것이라고 생각했습니다. –