How to detect, and color the left or right block of each table, depending on conditions and random values ​by JavaScript-jQ

huangapple go评论62阅读模式
英文:

How to detect, and color the left or right block of each table, depending on conditions and random values ​by JavaScript-jQ

问题

这是您提供的HTML和JavaScript代码的翻译结果。这部分是代码的翻译部分,不包括其他内容:

<!-- 开始代码片段:JavaScript 隐藏: false 控制台: true Babel: false -->

<!-- 语言: JavaScript -->
setInterval(function () {
    for (var i = 1; i <= 5; i++) {
        var number = 1 + Math.floor(Math.random() * 100);

        var getNum = $('#res' + i).html(number);
        if (getNum.html() >= 50) {
            $('#res' + i + 'mult').html("right");
            var num = 1;
            for (var j = 1; j <= 6; j++) {
                $("#row" + num++ + "-" + 2).css("background-color", 'red');
            }

        } else {
            var num2 = 1;
            $('#res' + i + 'mult').html("left");
            $("#row" + num2++ + "-" + num2).css("background-color", 'yellow');
        }

    }
}, 1000);

<!-- 语言: HTML -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>1</title>
    <script src="../!Needs/jquery.min.js"></script>
    <style>
        body {
            font-size: 20px;
        }

        table {
            width: 200px;
        }

        #shapedive {
            height: 500px;
            border-radius: 30pt;
        }
    </style>
</head>
<body>
<table>
    <tr>
        <td>
            <table id="bigTable" border="1" style="text-align: center;">
                <tr>
                    <td style="font-weight: bold">Pin</td>
                    <td style="font-weight: bold">Number</td>
                    <td style="font-weight: bold">Direction</td>
                </tr>
                <tr>
                    <td class="pin">1</td>
                    <td id="res1"></td>
                    <td id="res1mult"></td>
                </tr>
                <tr>
                    <td class="pin">2</td>
                    <td id="res2"></td>
                    <td id="res2mult"></td>
                </tr>
                <tr>
                    <td class="pin">3</td>
                    <td id="res3"></td>
                    <td id="res3mult"></td>
                </tr>
                <tr>
                    <td class="pin">4</td>
                    <td id="res4"></td>
                    <td id="res4mult"></td>
                </tr>
                <tr>
                    <td class="pin">5</td>
                    <td id="res5"></td>
                    <td id="res5mult"></td>
                </table>
            </td>
        </tr>
        <tr>
            <td id="shape">
                <div id="shapedive">
                    <table style="text-align: center" border="1">
                        <tr>
                            <td id="row1-1">*</td>
                            <td id="row1-2">Starter</td>
                            <td id="row1-3">*</td>
                        </tr>
                    </table>
                    <table style="text-align: center " border="1">
                        <tr>
                            <td id="row2-1">1</td>
                            <td id="row2-2">2</td>
                            <td id="row2-3">3</td>
                            <td id="row2-4">4</td>
                        </tr>
                    </table>
                    <table style="text-align: center " border="1">
                        <tr>
                            <td id="row3-1">1</td>
                            <td id="row3-2">2</td>
                            <td id="row3-3">3</td>
                            <td id="row3-4">4</td>
                            <td id="row3-5">5</td>
                        </tr>
                    </table>
                    <table style="text-align: center" border="1">
                        <tr>
                            <td id="row4-1">1</td>
                            <td id="row4-2">2</td>
                            <td id="row4-3">3</td>
                            <td id="row4-4">4</td>
                            <td id="row4-5">5</td>
                            <td id="row4-6">6</td>
                        </tr>
                    </table>
                    <table style="text-align: center" border="1">
                        <tr>
                            <td id="row5-1">1</td>
                            <td id="row5-2">2</td>
                            <td id="row5-3">3</td>
                            <td id="row5-4">4</td>
                            <td id="row5-5">5</td>
                            <td id="row5-6">6</td>
                            <td id="row5-7">7</td>
                        </tr>
                    </table>
                    <table style="text-align: center" border="1">
                        <tr>
                            <td id="row6-1">1</td>
                            <td id="row6-2">2</td>
                            <td id="row6-3">3</td>
                            <td id="row6-4">4</td>
                            <td id="row6-5">5</td>
                            <td id="row6-6">6</td>
                            <td id="row6-7">7</td>
                            <td id="row6-8">8</td>
                        </tr>
                    </table>
                </div>
            </td>
        </tr>
    </table>
    <br>
    
</body>
</html>

<!-- 结束代码片段 -->

希望这对您有所帮助。如果您有任何其他问题,请随时告诉我。

英文:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

setInterval(function () {
for (var i = 1; i &lt;= 5; i++) {
var number = 1 + Math.floor(Math.random() * 100);
var getNum = $(&#39;#res&#39; + i).html(number);
if (getNum.html() &gt;= 50) {
$(&#39;#res&#39; + i + &#39;mult&#39;).html(&quot;right&quot;);
var num = 1;
for (var j = 1; j &lt;= 6; j++) {
$(&quot;#row&quot; + num++ + &quot;-&quot; + 2).css(&quot;background-color&quot;, &#39;red&#39;);
}
} else {
var num2 = 1;
$(&#39;#res&#39; + i + &#39;mult&#39;).html(&quot;left&quot;);
$(&quot;#row&quot; + num2++ + &quot;-&quot; + num2).css(&quot;background-color&quot;, &#39;yellow&#39;);
}
}
},
1000);

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;1&lt;/title&gt;
&lt;script src=&quot;../!Needs/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;style&gt;
body {
font-size: 20px;
}
table {
width: 200px;
}
#shapedive {
height: 500px;
border-radius: 30pt;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table id=&quot;bigTable&quot; border=&quot;1&quot; style=&quot;text-align: center;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Pin&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Number&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Direction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;1&lt;/td&gt;
&lt;td id=&quot;res1&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res1mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;2&lt;/td&gt;
&lt;td id=&quot;res2&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res2mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;3&lt;/td&gt;
&lt;td id=&quot;res3&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res3mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;4&lt;/td&gt;
&lt;td id=&quot;res4&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res4mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;5&lt;/td&gt;
&lt;td id=&quot;res5&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res5mult&quot;&gt;&lt;/td&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;shape&quot;&gt;
&lt;div id=&quot;shapedive&quot;&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row1-1&quot;&gt;*&lt;/td&gt;
&lt;td id=&quot;row1-2&quot;&gt;Starter&lt;/td&gt;
&lt;td id=&quot;row1-3&quot;&gt;*&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row2-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row2-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row2-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row2-4&quot;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row3-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row3-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row3-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row3-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row3-5&quot;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row4-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row4-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row4-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row4-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row4-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row4-6&quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row5-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row5-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row5-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row5-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row5-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row5-6&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row5-7&quot;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row6-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row6-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row6-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row6-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row6-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row6-6&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row6-7&quot;&gt;7&lt;/td&gt;
&lt;td id=&quot;row6-8&quot;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;/body&gt;
&lt;/html&gt;

<!-- end snippet -->

I am trying to make a simple game. We have two tables. The table on the top, which has 5 rows and 3 columns - including: pin, random number and direction (left or right) - and the bottom table which has 6 rows. The cell at the first row and second column ($(&quot;#row1-2&quot;)) is the beginning of our game.

The Left/Right values in the top table determine the direction, left or right, of the cell that should be painted in the corresponding row in the bottom table.

We have a simple condition to get a direction value. We generate a random number. If the random number is > 50, the direction is set to &quot;right&quot;; otherwise, it is set to &quot;left&quot;.

That is, if, for example, the values ​​in the top table were as follows:

Pin 1 =&gt; 28 =&gt; Left

Pin 2 =&gt; 9 =&gt; Left

Pin 3 =&gt; 56 =&gt; Right

Pin 4 =&gt; 99 =&gt; Right

Pin 5 =&gt; 14 =&gt; Left

Then, in the bottom table, the game is started from the starter column, and as we incrementally descend the rows, the column that gets painted is determined by the &quot;left&quot; or &quot;right&quot; values that were generated above.

In the bottom table, because the value of pin 1 (28) is less than 50, the painted column will move to the &quot;left&quot; from the starter block $(&quot;#row1-2&quot;): $(&quot;#row2-2&quot;).

And because the value of pin 2 (9) also maps to &quot;left&quot;, the painted column in the next row should also be to the &quot;left&quot;: $(&quot;#row3-2&quot;).

For pin 3, we have &quot;right&quot;, so the column in the next row to the right of the last painted cell should be painted: $(&quot;#row4-3&quot;).

...and so on until all the rows have a painted cell.


&lt;!DOCTYPE html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
&lt;meta charset=&quot;UTF-8&quot;&gt;
&lt;title&gt;1&lt;/title&gt;
&lt;script src=&quot;../!Needs/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;style&gt;
body {
font-size: 20px;
}
table {
width: 200px;
}
#shapedive {
height: 500px;
border-radius: 30pt;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table id=&quot;bigTable&quot; border=&quot;1&quot; style=&quot;text-align: center;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Pin&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Number&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Direction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;1&lt;/td&gt;
&lt;td id=&quot;res1&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res1mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;2&lt;/td&gt;
&lt;td id=&quot;res2&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res2mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;3&lt;/td&gt;
&lt;td id=&quot;res3&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res3mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;4&lt;/td&gt;
&lt;td id=&quot;res4&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res4mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;5&lt;/td&gt;
&lt;td id=&quot;res5&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res5mult&quot;&gt;&lt;/td&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;shape&quot;&gt;
&lt;div id=&quot;shapedive&quot;&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row1-1&quot;&gt;*&lt;/td&gt;
&lt;td id=&quot;row1-2&quot;&gt;Starter&lt;/td&gt;
&lt;td id=&quot;row1-3&quot;&gt;*&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row2-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row2-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row2-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row2-4&quot;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row3-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row3-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row3-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row3-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row3-5&quot;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row4-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row4-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row4-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row4-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row4-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row4-6&quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row5-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row5-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row5-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row5-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row5-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row5-6&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row5-7&quot;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row6-1&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row6-2&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row6-3&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row6-4&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row6-5&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row6-6&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row6-7&quot;&gt;7&lt;/td&gt;
&lt;td id=&quot;row6-8&quot;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;br&gt;
&lt;script&gt;
setInterval(function () {
for (var i = 1; i &lt;= 5; i++) {
var number = 1 + Math.floor(Math.random() * 100);
var getNum = $(&#39;#res&#39; + i).html(number);
if (getNum.html() &gt;= 50) {
$(&#39;#res&#39; + i + &#39;mult&#39;).html(&quot;right&quot;);
var num = 1;
for (var j = 1; j &lt;= 6; j++) {
$(&quot;#row&quot; + num++ + &quot;-&quot; + 2).css(&quot;background-color&quot;, &#39;red&#39;);
}
} else {
var num2 = 1;
$(&#39;#res&#39; + i + &#39;mult&#39;).html(&quot;left&quot;);
$(&quot;#row&quot; + num2++ + &quot;-&quot; + num2).css(&quot;background-color&quot;, &#39;yellow&#39;);
}
}
},
1000);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

答案1

得分: 1

我发现在顶部表格中的单元格与第二个表格中的单元格进行同步非常困难。一个问题是第一个表格中的第一行有一个左/右值;但在第二个表格中,第一行是“Starter” - 左/右决策直到第二行才开始。我建议通过使两个表格中的对应行具有相同的编号来简化此问题。我还建议将行和列从0开始编号(而不是从1开始),因为这对我的大脑更容易理解,与数组和典型的循环一致。

要确定在遍历表格时哪一列是活动列,对我来说有帮助的是认识到“左”步骤意味着下一行中列索引保持不变,而“右”步骤意味着索引增加1。

我们可以声明一个变量来跟踪当前列。我们将从1开始,因为我们知道“Starter”位于其行的[1]索引处:const col = 1;。然后,当我们遍历行时,如果向右移动,则将col增加1,如果向左移动,则增加0。

我们可以将游戏逻辑打包到一个名为play的函数中,然后一次调用它 - play() - 或在间隔内调用它 - setInterval(play, 1000)

const play = () => {
  let col = 1;

  // 重置游戏板
  $('td').css('background-color', 'white');
  $('td#starter').css('background-color', 'red');

  for (let row = 0; row < 6; row++) {
    const pin = 1 + Math.floor(Math.random() * 100);
    const isRight = pin > 50;

    col += (isRight ? 1 : 0);

    $(`#res${row}`).text(pin);
    $(`#res${row}mult`).text(isRight ? 'right' : 'left');
    $(`#row${row}-${col}`).css("background-color", isRight ? 'yellow' : 'red');
  }
};

play();
// setInterval(play, 1000);

我还创建了一个示例fiddle

英文:

I find it very difficult to synchronize the cells in the top table with those in the second. One problem is that row 1 in the first table has a left/right value; but in the second table, row 1 is the Starter - the left/right decisions don't start until row 2. I would simplify this by making the corresponding rows in the two tables have the same number. I would also 0-index the rows and columns (as opposed to having them start at 1) because this is easier for my brain as it is consistent with arrays and typical loops.

To determine which column is active as we descend the table, it was helpful for me to realize that a "left" step means the column index stays the same in the next row, and a "right" step means the index increases by 1.

We can declare a variable to track the current column. We will start it at 1 since we know the "Starter" is at the [1] index of its row: const col = 1;. Then, as we loop through the rows, we increment col by 1 if we are stepping right or 0 if we are stepping left.

We can package our game logic into a play function and invoke it once - play() - or at an interval - setInterval(play, 1000).

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

const play = () =&gt; {
let col = 1;
// reset the game board
$(&#39;td&#39;).css(&#39;background-color&#39;, &#39;white&#39;);
$(&#39;td#starter&#39;).css(&#39;background-color&#39;, &#39;red&#39;);
for (let row = 0; row &lt; 6; row++) {
const pin = 1 + Math.floor(Math.random() * 100);
const isRight = pin &gt; 50;
col += (isRight ? 1 : 0);
$(`#res${row}`).text(pin);
$(`#res${row}mult`).text(isRight ? &#39;right&#39; : &#39;left&#39;);
$(`#row${row}-${col}`).css(&quot;background-color&quot;, isRight ? &#39;yellow&#39; : &#39;red&#39;);
}
};
play();
//setInterval(play, 1000);

<!-- language: lang-css -->

body {
font-size: 20px;
}
table {
width: 200px;
}
#shapedive {
height: 500px;
border-radius: 30pt;
}

<!-- language: lang-html -->

&lt;script src=&quot;https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js&quot;&gt;&lt;/script&gt;
&lt;table&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;table id=&quot;bigTable&quot; border=&quot;1&quot; style=&quot;text-align: center;&quot;&gt;
&lt;tr&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Pin&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Number&lt;/td&gt;
&lt;td style=&quot;font-weight: bold&quot;&gt;Direction&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;1&lt;/td&gt;
&lt;td id=&quot;res0&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res0mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;2&lt;/td&gt;
&lt;td id=&quot;res1&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res1mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;3&lt;/td&gt;
&lt;td id=&quot;res2&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res2mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;4&lt;/td&gt;
&lt;td id=&quot;res3&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res3mult&quot;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class=pin&gt;5&lt;/td&gt;
&lt;td id=&quot;res4&quot;&gt;&lt;/td&gt;
&lt;td id=&quot;res4mult&quot;&gt;&lt;/td&gt;
&lt;/table&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td id=&quot;shape&quot;&gt;
&lt;div id=&quot;shapedive&quot;&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;td id=&quot;starter&quot;&gt;Starter&lt;/td&gt;
&lt;td&gt;*&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row0-0&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row0-1&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row0-2&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row0-3&quot;&gt;4&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center &quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row1-0&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row1-1&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row1-2&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row1-3&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row1-4&quot;&gt;5&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row2-0&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row2-1&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row2-2&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row2-3&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row2-4&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row2-5&quot;&gt;6&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row3-0&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row3-1&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row3-2&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row3-3&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row3-4&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row3-5&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row3-6&quot;&gt;7&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;table style=&quot;text-align: center&quot; border=&quot;1&quot;&gt;
&lt;tr&gt;
&lt;td id=&quot;row4-0&quot;&gt;1&lt;/td&gt;
&lt;td id=&quot;row4-1&quot;&gt;2&lt;/td&gt;
&lt;td id=&quot;row4-2&quot;&gt;3&lt;/td&gt;
&lt;td id=&quot;row4-3&quot;&gt;4&lt;/td&gt;
&lt;td id=&quot;row4-4&quot;&gt;5&lt;/td&gt;
&lt;td id=&quot;row4-5&quot;&gt;6&lt;/td&gt;
&lt;td id=&quot;row4-6&quot;&gt;7&lt;/td&gt;
&lt;td id=&quot;row4-7&quot;&gt;8&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;

<!-- end snippet -->

I have also created an example fiddle.

huangapple
  • 本文由 发表于 2023年2月18日 00:38:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75486975.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定