毎度お世話になっております。
coffee
1 2move = (direction = "top", minus = 1) -> 3 $('.falling').each(fun = () -> # 4 blockCSS = parseInt($(this).css("#{direction}").slice(0, -2)) 5 # blockBottom = parseInt($(this).css("bottom").slice(0, -2)) 6 # blockRight = parseInt($(this).css("right").slice(0, -2)) 7 if minus == 1 8 blockCSS += 30 if blockCSS < 600 9 else 10 blockCSS -= 30 if blockCSS > 0 11 console.log(blockCSS) 12 $(this).css("#{direction}", blockCSS) 13 ) 14 15$(window).on "keydown", (e) -> 16 # bot = $('#field').css("bottom") 17 # console.log bot 18 switch e.keyCode 19 when 40 20 move() 21 when 39 22 move("left", 1) 23 when 37 24 move("left", -1) 25 when 32 26 setInterval("move()", 1000) #<----ここ 27
このようなコードを書きましたが、なぜかsetIntervalのところでmove is not defined
と言われてしまいます。他のWhenだと普通に動くのに、なぜかsetInterbalのところで参照エラー。
どなたか、解決策をご教授くださるとありがたいです。ちなみにコンパイルされたコードはこちら。
js
1// Generated by CoffeeScript 1.10.0 2(function() { 3 var move; 4 5 move = function(direction, minus) { 6 var fun; 7 if (direction == null) { 8 direction = "top"; 9 } 10 if (minus == null) { 11 minus = 1; 12 } 13 return $('.falling').each(fun = function() { 14 var blockCSS; 15 blockCSS = parseInt($(this).css("" + direction).slice(0, -2)); 16 if (minus === 1) { 17 if (blockCSS < 600) { 18 blockCSS += 30; 19 } 20 } else { 21 if (blockCSS > 0) { 22 blockCSS -= 30; 23 } 24 } 25 console.log(blockCSS); 26 return $(this).css("" + direction, blockCSS); 27 }); 28 }; 29 30 $(window).on("keydown", function(e) { 31 switch (e.keyCode) { 32 case 40: 33 return move(); 34 case 39: 35 return move("left", 1); 36 case 37: 37 return move("left", -1); 38 case 32: 39 return setInterval("move()", 1000); 40 } 41 }); 42 43}).call(this); 44
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。