クリックで始まるアニメーションを作成したのですが、クリックしたらアニメーション
が終了するまで、画像をクリックできないようにするためにclick_flgを使いました。
しかし、何かが原因でfalseの方は効いてもtrueの方は効きません。
どなたか教えて下さい。
HTML5
1<body id="firework"> 2 3 <div id="shoot"> 4 <figure class="img1"><img src="images/canon.png" alt="canon" id="canon"></figure> 5 <figure class="img2"><img src="images/machi.png" alt="machi" id="match"></figure> 6 <figure class="img3"><img src="images/firework.png" alt="firework" id="fire"></figure> 7 <figure class="img4"><img src="images/fire-ball.png" alt="fire-ball" id="ball"></figure> 8 </div>
CSS3
1#match { 2 opacity: 0; 3} 4 5#fire { 6 opacity: 0; 7} 8 9.img4 { 10 position: absolute; 11 right: 29px; 12 top: auto; 13 bottom: -8px; 14 z-index: -100; 15 opacity: 0; 16} 17 18.firework { 19 position: relative; 20 height: 100%; 21} 22 23#canon { 24 position: absolute; 25 right: 30px; 26 bottom: 0; 27} 28 29.img2 { 30 position: absolute; 31 right: -100px; 32 bottom: 50px; 33 z-index: -99; 34 // transform: translateY(10px); 35 // transition: all .1s; 36} 37 38.img3 { 39 position: fixed; 40 right: 0; 41 top: 0; 42} 43 44#shoot { 45 position: absolute; 46 width: 100px; 47 height: 100px; 48 right: 30px; 49 bottom: 0; 50}
jQuery
1$(function (){ 2 3 var click_flg = true; 4 5 $('#canon').on('click',function() { 6 7 if(click_flg){ 8 9 click_flg = false; 10 11 matchin().done(function(){ 12 13 shoot(); 14 15 // sound(); 16 17 }); 18 19 }); 20 function matchin() { 21 22 var d = $.Deferred(); 23 24 $('#match').animate({opacity: 1},1000); 25 26 $('.img2').animate({"bottom": "-10px"},1000), 27 28 $('.img2').animate({"bottom": "60px"},1000), 29 30 $('#match').animate({opacity: 0},1000,function() { 31 32 d.resolve(); 33 34 }); 35 36 return d.promise(); 37 38 } 39 40 41 function shoot() { 42 43 $('.img4').animate({opacity: 1},1000); 44 45 $('html,body').animate({scrollTop: 0},2500,"swing"); 46 47 $('.img4').animate({top: -650},3000,"swing",function(){ 48 49 $('.img4').css('top','auto'), 50 51 $('#fire').animate({opacity: 1},300), 52 53 $('#fire').animate({opacity: 0},1500); 54 55 click_flg = true; 56 57 }); 58 59 } 60 61 } 62 63 // function sound(){ 64 65 // $('#sound-file').get(0).play(); 66 67 // } 68 69 });
回答1件
あなたの回答
tips
プレビュー