2016-10-05 15 views
-2

ボタンをクリックして、最初のクリックと2回目のクリックをトリガーします。だから、複数回クリックすると、アニメーションが壊れてしまいます。jqueryで複数回クリックするとボタンをクリックしないようにします

アニメーション中にクリックを無効にし、アニメーションが完了したときにのみ有効にする方法はありますか?小道具と

私のコードは、以下を参照してくださいここでは、適切

jQuery('.start_button').click(function(event){ 
    jQuery(this).find('button').prop('disabled', true); 
    if(clickcount === 0){ 
     jQuery(this).find('button').prop('disabled', true); 
     wheelForuneAnim.startAnimation(); 
     jQuery(this).find('button').prop('disabled', false); 
     clickcount = 1; 
    } 
    else if(clickcount === 1){ 
     jQuery(this).find('button').prop('disabled', true); 
     wheelForuneAnim.stopFull(); 
     setTimeout(function(){ 
      wheelForuneAnim.stopAnimation(); 
     }, 700); 
     clickcount = 0; 

    }; 
}); 

作業されていないdisbledマークアップ

<div class="start_button"> 
     <button type="button"></button> 
</div> 

方法

startAnimation = function() { 
     interval = setInterval(this.animation, 250); 
    }; 
animation = function() { 
     if((wheelelement % elems.length)==0){ wheelelement = 0 ;} 
     elems.removeClass('active_wheel'); 
     jQuery('.game_wheel_item:eq('+wheelelement+')').addClass('active_wheel'); 
     wheelelement++; 
    }; 

この問題を解決するためにどのように任意のアイデアですか?

+1

私は

+2

だから '.start_button'はボタンを含む悪い名前の' div'要素ですか?ここであなたの実際のHTMLを見てください。 –

+0

更新された質問を参照してください。@RoryMcCrossan –

答えて

0

コードの下に、コードの多くはあなたの問題を解決することを不要

jQuery('.start_button').on('click','button',function(event){ 
    jQuery(this).off('click','button'); 

     wheelForuneAnim.startAnimation(function() 
     { 
      // do your second if stuff 
      setTimeout(function(){ 
       wheelForuneAnim.stopAnimation(function() 
       { 
         // after function finished executing do some stuff here 
       }); 
       jQuery(this).on('click','button'); 
      }, 700); 
     }); 
}); 

あなたの方法

startAnimation = function (cbck) { 
     interval = setInterval(this.animation, 250); 
     if(cbck) 
     { 
      cbck(); 
     } 
    }; 
stopanimation = function (cbck) { 
     if((wheelelement % elems.length)==0){ wheelelement = 0 ;} 
     elems.removeClass('active_wheel'); 
     jQuery('.game_wheel_item:eq('+wheelelement+')').addClass('active_wheel'); 
     wheelelement++; 

     if(cbck) 
      cbck(); 
    }; 
+0

なぜ 'setTimeout'ですか? – Satpal

+0

if文をオン/オフで追加すると正しく動作しません@Keerthivasan –

+0

リンクを提供してください(参考)ので、コードを提供した実際のユーザーにクレジットが送られて、回答をコピーして投稿しないでください。 –

0

あなたは常にこのようにそれをやろうとすることができる。

jQuery('.start_button button').click(function(event) { //This gets the button in the div 

    var button = jQuery(this); 

    if (buttonText(button.text()) === "Start") { 
    wheelForuneAnim.startAnimation(); 
    button.text('Stop') 
    } else { 
    wheelForuneAnim.stopFull(); 
    setTimeout(function() { 
     wheelForuneAnim.stopAnimation(); 
     button.text('Start') 
    }, 700); 
    } 
}) 

function buttonText(text) { 
    if (text === "Start") { 
    return "Start" 
    } else { 
    return "Stop" 
    } 
} 

このボタンを無効にすることはありませんが、アニメーションが壊れるのを防ぐのに役立つと思います。

+0

ボタンを無効にする場所がどこにあるのかは同じ状況と問題のようです。何か案は?私はさまざまな変種を試しましたが、まだ何も良い@ Zorken17。また、同じボタンを2度目にクリックしたときに別のアノテーションが停止するだけではなく、それが問題です –

関連する問題