123

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <header>
  <h1>Fool's Mate</h1>
  <p>In chess, Fool's Mate, also known as the Two-Move Checkmate, is the checkmate in the fewest possible number of moves from the start of the game. This can be achieved only by Black, who can deliver checkmate on move 2 with the queen. Fool's Mate received its name because it can only occur if White commits an extraordinary blunder. Even among rank beginners, the mate almost never occurs in practice.</p>
</header>

<main>
  <div class="grid board">
    <div class="grid__item piece">♜</div>
    <div class="grid__item piece">♞</div>
    <div class="grid__item piece">♝</div>
    <div class="grid__item piece">♚</div>
    <div class="grid__item piece">♝</div>
    <div class="grid__item piece">♞</div>
    <div class="grid__item piece">♜</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece">♟</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row7">♙</div>
    <div class="grid__item piece row8">♖</div>
    <div class="grid__item piece row8">♘</div>
    <div class="grid__item piece row8">♗</div>
    <div class="grid__item piece row8">♕</div>
    <div class="grid__item piece row8">♔</div>
    <div class="grid__item piece row8">♗</div>
    <div class="grid__item piece row8">♘</div>
    <div class="grid__item piece row8">♖</div>
  </div>

  <div class="move1 grid">
    <div class="piece"><span>♙</span></div>
  </div>

  <div class="move2 grid">
    <div class="piece"><span>♟</span></div>
  </div>

  <div class="move3 grid">
    <div class="piece"><span>♙</span></div>
  </div>

  <div class="move4 grid">
    <div class="piece"><span>♛</span></div>
  </div>
</main>

<div class="controls">
  <button type="button" id="prev">Prev</button>
  <button type="button" id="next">Next</button>
</div>
            
          
!
            
              @font-face {
  font-family: "Emoji";
  src: local("Apple Color Emoji"), local("Segoe UI Emoji"), local("Segoe UI Symbol"), local("Noto Color Emoji");
}

body {
  display: flex;
  flex-direction: column;
  text-align: center;
  align-items: center;
}

p {
  line-height: 1.4;
}

.board {
  background-color: #eee;
  background-image: linear-gradient(45deg, #d18b47 25%, transparent 25%, transparent 75%, #d18b47 75%, #d18b47),
  linear-gradient(45deg, #d18b47 25%, transparent 25%, transparent 75%, #d18b47 75%, #d18b47);
  background-size: 24vmin 24vmin;
  background-position: 0 0, 12vmin 12vmin;
  width: 96vmin;
  height: 96vmin;
  margin: auto;
}

.piece {
  font-size: 6vmin;
  font-family: "Emoji";
}

main {
  position: relative;
  height: 96vmin;
  width: 96vmin;
}

.grid {
  display: grid;
  position: absolute;
}

.board {
  grid-template-columns: repeat(8, 12vmin);
  grid-template-rows: repeat(8, 12vmin);
}

.board .grid__item {
  margin: auto;
}

.board .piece:nth-child(4) { grid-column: 5 }
.board .piece:nth-child(12) { grid-column: 6 }
.board .piece:nth-child(20) { grid-column: 8 }
.row7 { grid-row: 7 }
.row8 { grid-row: 8 }

[class^="move"] {
  height: 100%;
  width: 100%;
}

[class^="move"] .piece {
  height: 12vmin;
  width: 12vmin;
  display: flex;
  place-self: end;
}

[class^="move"] span {
  margin: auto;
}

.move1 {
  grid-template-columns: 72vmin 1fr;
  grid-template-rows: 84vmin 1fr;
  transition: grid-template-rows 0.5s linear;
}

.move1.active {
  grid-template-rows: 72vmin 1fr;
}

.move2 {
  grid-template-columns: 60vmin 1fr;
  grid-template-rows: 24vmin 1fr;
  transition: grid-template-rows 0.75s linear;
}

.move2.active {
  grid-template-rows: 48vmin 1fr;
}

.move3 {
  grid-template-columns: 84vmin 1fr;
  grid-template-rows: 84vmin 1fr;
  transition: grid-template-rows 0.75s linear;
}

.move3.active {
  grid-template-rows: 60vmin 1fr;
}

.move4 {
  grid-template-columns: 48vmin 1fr;
  grid-template-rows: 12vmin 1fr;
  transition: grid-template-columns 1.25s linear, grid-template-rows 1.25s linear;
}

.move4.active {
  grid-template-columns: 96vmin 1fr;
  grid-template-rows: 60vmin 1fr;
}

.controls {
  width: 36vmin;
  display: flex;
  margin-top: 1em;
  justify-content: space-around;
}

button {
  font-size: initial;
  background-color: #d18b47;
  border: none;
  padding: 0.5em 0.75em;
  cursor: pointer;
}
            
          
!
            
              const prevBtn = document.getElementById('prev')
const nextBtn = document.getElementById('next')

let moves = 0

prevBtn.addEventListener('click', prevHandler, false)
nextBtn.addEventListener('click', nextHandler, false)

function nextHandler() {
  if (moves < 4) {
    countUp()
    addActive(moves)
    console.log(moves)
  } else {
    console.log('Already checkmate')
  }
}

function prevHandler() {
  if (moves > 0) {
    removeActive(moves)
    countDown()
    console.log(moves)
  } else {
    console.log('Back to the start')
  }
}

function addActive(moves) {
  const activeMove =  document.querySelector('.move' + moves)
  activeMove.classList.add('active')
}

function removeActive(moves) {
  const activeMove =  document.querySelector('.move' + moves)
  activeMove.classList.remove('active')
}

function countUp() {
  return moves++
}

function countDown() {
  return moves--
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console