2017-01-29 16 views
0

私はjavascriptを使用してゲームを作成しようとしていますが、Firefoxにはバグが見つかりました。ゲームは簡単です。あなたは、RGBのhexacodeにどのような色があるのか​​推測する必要があります。 6つのボックスがあります。ボックスをクリックすると、間違っているか正しく表示されます。 Mozilla Firefoxで動作しない間、Chrome、IE、Operaでゲームは正常に動作しています。私はそれをデバッグするための警告を出し、Firefoxはそれを使っていくつかのインラインスタイルを追加します。下記のスクリーンショットとコードをご覧ください。うまくいけば、Firefoxでこの問題を解決する方法を教えてください。事前のおかげでMozillaブラウザのバグ

FIREFOX SCREENSHOT PROBLEM CHROME SCREENSHOT NO PROBLEM

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Color Game</title> 
 
<style type="text/css"> 
 
\t body{ 
 
\t \t background-color: #232323; 
 
\t } 
 

 
\t h1 { 
 
\t \t color:#fff; 
 
\t } 
 
\t .square { 
 
\t \t width: 30%; 
 
\t \t background: purple; 
 
\t \t padding-bottom: 30%; 
 
\t \t float: left; 
 
\t \t margin: 1.66%; 
 
\t } 
 

 
\t #container { 
 
\t \t max-width: 600px; 
 
\t \t margin: 0px auto; 
 
\t } 
 
</style> 
 
</head> 
 
<body> 
 

 
<h1>Guess what color is<span id="colorDisplay">RGB</span> 
 
<br/> 
 
Click the box to know what color it is. 
 
</h1> 
 

 
<div id="container"> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
</div> 
 

 
<script type="text/javascript"> 
 
\t 
 
\t var colors = [ 
 
\t "rgb(255, 0, 0)", 
 
\t "rgb(255, 255, 0)", 
 
\t "rgb(0, 255, 0)", 
 
\t "rgb(0, 255, 255)", 
 
\t "rgb(0, 0, 255)", 
 
\t "rgb(255, 0, 255)" 
 
\t ]; 
 

 
\t var squares = document.querySelectorAll(".square"); 
 
\t var pickedColor = colors[1]; 
 
\t var colorDisplay = document.querySelector("#colorDisplay"); 
 

 
\t colorDisplay.textContent = pickedColor; 
 

 
\t for (var i=0; i<squares.length; i++){ 
 
\t \t //add initial colors to square 
 
\t \t squares[i].style.background = colors[i]; 
 
\t \t //add click listener to square 
 
\t \t squares[i].addEventListener("click",function(){ 
 
\t \t \t var clickedColor = this.style.background; 
 
\t \t \t alert(clickedColor); 
 
\t \t \t if (clickedColor === pickedColor){ 
 
\t \t \t \t alert("Correct"); 
 
\t \t \t } else{ 
 
\t \t \t \t alert("Wrong"); 
 
\t \t \t } 
 
\t \t }); 
 
\t } 
 

 
</script> 
 

 
</body> 
 
</html>

+0

ありがとうございました! – JackOfAllTrades

答えて

1

代わりbackground速記のbackgroundColorプロパティを使用してみてください:

var colors = [ 
    "rgb(255, 0, 0)", 
    "rgb(255, 255, 0)", 
    "rgb(0, 255, 0)", 
    "rgb(0, 255, 255)", 
    "rgb(0, 0, 255)", 
    "rgb(255, 0, 255)" 
    ]; 

    var squares = document.querySelectorAll(".square"); 
    var pickedColor = colors[1]; 
    var colorDisplay = document.querySelector("#colorDisplay"); 

    colorDisplay.textContent = pickedColor; 

    for (var i=0; i<squares.length; i++){ 
     //add initial colors to square 
     squares[i].style.background = colors[i]; 
     //add click listener to square 
     squares[i].addEventListener("click",function(){ 
      var clickedColor = this.style.backgroundColor; 
      alert(clickedColor); 
      if (clickedColor === pickedColor){ 
       alert("Correct"); 
      } else{ 
       alert("Wrong"); 
      } 
     }); 
    } 
+0

ありがとう、それは動作します!感謝します! – JackOfAllTrades

+0

ようこそ。うまくいきました:) –

1

ないFirefoxのバグを。あなたがこの作品

など、それ以外の場合は、カラープラスno-repeat scrollを取得します、backgroundColorを指定する必要があります。私の理解から

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>Color Game</title> 
 
<style type="text/css"> 
 
\t body{ 
 
\t \t background-color: #232323; 
 
\t } 
 

 
\t h1 { 
 
\t \t color:#fff; 
 
\t } 
 
\t .square { 
 
\t \t width: 30%; 
 
\t \t background: purple; 
 
\t \t padding-bottom: 30%; 
 
\t \t float: left; 
 
\t \t margin: 1.66%; 
 
\t } 
 

 
\t #container { 
 
\t \t max-width: 600px; 
 
\t \t margin: 0px auto; 
 
\t } 
 
</style> 
 
</head> 
 
<body> 
 

 
<h1>Guess what color is<span id="colorDisplay">RGB</span> 
 
<br/> 
 
Click the box to know what color it is. 
 
</h1> 
 

 
<div id="container"> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
\t <div class="square"> </div> 
 
</div> 
 

 
<script type="text/javascript"> 
 
\t 
 
\t var colors = [ 
 
\t "rgb(255, 0, 0)", 
 
\t "rgb(255, 255, 0)", 
 
\t "rgb(0, 255, 0)", 
 
\t "rgb(0, 255, 255)", 
 
\t "rgb(0, 0, 255)", 
 
\t "rgb(255, 0, 255)" 
 
\t ]; 
 

 
\t var squares = document.querySelectorAll(".square"); 
 
\t var pickedColor = colors[1]; 
 
\t var colorDisplay = document.querySelector("#colorDisplay"); 
 

 
\t colorDisplay.textContent = pickedColor; 
 

 
\t for (var i=0; i<squares.length; i++){ 
 
\t \t //add initial colors to square 
 
\t \t squares[i].style.background = colors[i]; 
 
\t \t //add click listener to square 
 
\t \t squares[i].addEventListener("click",function(){ 
 
\t \t \t var clickedColor = String(this.style.backgroundColor); 
 
\t \t \t alert(clickedColor); 
 
\t \t \t if (clickedColor === pickedColor){ 
 
\t \t \t \t alert("Correct"); 
 
\t \t \t } else{ 
 
\t \t \t \t alert("Wrong"); 
 
\t \t \t } 
 
\t \t }); 
 
\t } 
 

 
</script> 
 

 
</body> 
 
</html>

+0

今すぐ助けてくれてありがとう! – JackOfAllTrades

0

を、それは背景とは何かを持っています。スクロールしないスクロールは、通常、バックグラウンドに関連するプロパティです。 Andresによってコメントされた上記のコードはあなたを助けます。がんばろう。

関連する問題