Pen Settings

HTML

CSS

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

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <h1>Chess game display</h1>
<div id="suportRange">S<br>i<br>z<br>e<br><br> <input type="range" min="6" max="11" value="8" oninput="boardSize()"></div>
<div class="center">
<select id="chessGames" onchange="game()">
<option>Select a game</option>   
<option value="foolsMate">Fool's mate</option>
<option value="scholarsMate">Scholar's mate</option>
<option value="legalTrap">Légal Trap</option> 
</select>
<div id="textEnd">fgf</div>

<div id="border"><div id="container"></div></div>
</div>
<div id="move"></div>
<script>
if (/Edge/.test(navigator.userAgent)) {
document.write('Microsoft Edge, paints the black pawn out of range (♟ ♙).  :(  . Use another browser :)');
}
</script>
<ul id="info">·</ul>
<ul style="list-style: none">
<li>Version: <b>A first approach</b></li> 
<li>
<author style="margin:10px;display:block"> 
<img style="width: 40px; border-radius: 50%;vertical-align: middle; background-color:black;transform:scale(-1,1)" src="https://s.cdpn.io/profiles/user/3103547/512.jpg?1555236072" alt="Avatar of Jomohop"> by 
<a href="https://codepen.io/jomohop"  target="_blank" style="color:black; font-size: 18px;vertical-align: middle"> Jomohop</a> 
</author>
</li> 
</ul>
            
          
!

CSS

            
              :root{
--edge:;
}
html,body{
height: 100%;
margin:0;
}
body{
background-image: linear-gradient(75deg,white,  lightgray 5%,white 15%, lightgray 55% , lightgray 90%,white);
background-size: 100%;
background-attachment: fixed;
min-height: 300px;
font-family:sans-serif;
overflow-x: hidden;
}
h1{
line-height: 24px;;
margin: 0;
font-weight: normal;
}
a{
color:black;
}
.center{
text-align: center;
}
#border{
display:inline-block;
margin:auto;
padding:calc(var(--edge)/3);
background-color: white;
}
#container{
width:calc(8*var(--edge)); 
height: calc(8*var(--edge));
margin: auto;
background-color: blue;
background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg'  width='200' height='200' fill-opacity='1'><rect width='200' height='200' fill='white' /><rect width='100' height='100' x='100'  fill='darkgray' /><rect width='100' height='100' y='100'  fill='darkgray' /></svg>");
background-size: 25%;
}

#container>div,#move{
width: var(--edge);
height:var(--edge);
display:inline-block;
vertical-align: top;
text-align: center;
line-height: var(--edge);
font-size:  calc(0.95*var(--edge));
text-shadow: 0 0 2vmin black;
}
#move{
position: absolute;
width: var(--edge);
height:var(--edge);
transition:.4s ease-in-out;
}

#suportRange{
position: absolute;
width: 20px;
margin:2px;
font-size: 18px;
text-align: center;
height: 200px;
line-height: 16px;
padding-top: 20px;
background-color: lightgray;
}
#suportRange>input{
transform-origin:left  top ;
transform:rotate(90deg) translateY(-19px);
width: 100px;
}
#chessGames{
width: 250px;
height: 30px;
font-size: 20px;
border:2px solid white;
background-color: white;

}
#chessGames>option:first-child {
display:none;
}
#chessGames:disabled{
color:dimgray;
     
}
#textEnd{
color:#cc0000;
line-height:30px;
font-size: 20px;
min-height: 30px;
text-align: center;
}
            
          
!

JS

            
              document.addEventListener("DOMContentLoaded",function(){
    var div,i    
    for(i = 0 ; i < 64 ; i++){
        div = document.createElement("DIV")
        div.title = i
        document.getElementById("container").appendChild(div)
    }
    
    root = document.documentElement
    select = document.getElementById("chessGames")
    textEnd = document.getElementById("textEnd")
    info = document.getElementById("info")
    box = document.querySelectorAll("#container>div")
    move = document.getElementById("move")
    
    document.querySelector("#chessGames>option:first-child").selected = true

    boardSize()
    putPieces()
}) 
function gameData(current){
    var i , tmp = ""
    for (i in current.gameData){
        tmp += "<li>" + i + ":<b> "  + current.gameData[i] + "</b>"
    }
    info.innerHTML = tmp +
                    '<li>Wikipedia: <a href="' +
                        current.info +
                    '" target="_blank">' +
                        current.title +
                    '</a>'
}
function game(){    
    var playNow = select.value
    var current = annotation[playNow]
    putPieces()
    gameData(current)
    select.disabled = true
    current.play.forEach(function(play,i){
        setTimeout(function(){
            movePiece(play[0],play[1])
        }, i * 900)
    }) 
     setTimeout(function(){
         endGame(current.lose,current.end)
    },900 * current.play.length)
}
function endGame(lose,phrase){    
    var index = 0
    while(box[index].innerHTML != lose){
        index++
    }
    box[index].setAttribute("style","transition:transform 1s ease .15s;transform:rotate(-90deg);text-shadow: 0 0 1vmin red;")
    setTimeout(function(){
            textEnd.innerHTML = phrase
            select.disabled = false
    },1000)
}
function boardSize(){
    root.style.setProperty('--edge',document.querySelector("#suportRange>input").value + "vmin") 
}
function putPieces(){
    box.forEach(function(box){
        box.innerHTML = ""
        box.removeAttribute("style")
     })
    textEnd.innerHTML = ""
    var blacks= "♜,♞,♝,♛,♚,♝,♞,♜," +
                "♟,♟,♟,♟,♟,♟,♟,♟"    
    blacks.split(",").forEach(function(piece,i){
        box[i].innerHTML = piece
    })
    var whites = "♙,♙,♙,♙,♙,♙,♙,♙," +
                 "♖,♘,♗,♕,♔,♗,♘,♖"  
    whites.split(",").forEach(function(piece,i){
        box[i+48].innerHTML = piece
    })
}


    
function movePiece(from,to){
    var from = box[from]
    var to = box[to]
    move.style.transition = "0s"
    move.style.left = from.offsetLeft + "px"
    move.style.top = from.offsetTop + "px"
    move.innerHTML = from.innerHTML
    from.innerHTML = ""
    setTimeout(function(){ 
        move.style.transition = ""
        move.style.left = to.offsetLeft + "px"
        move.style.top = to.offsetTop + "px"        
        setTimeout(function(){
            to.innerHTML = move.innerHTML
            move.innerHTML = ""
        },400)
    },400)
}
blackKing="♚"
whiteKing="♔"    
annotation = {
    foolsMate : {
        title : "Fool's mate",
        play : [
            [53,45],[12,28],[54,38],[3,39]
        ],
        end : "The fastest checkmate",
        lose : whiteKing,
        info : "https://en.wikipedia.org/wiki/Fool%27s_mate",
        gameData :{},
    },
    scholarsMate : {
        title : "Scholar's mate",
        play : [
            [52,36],[12,28],[59,31],[1,18],[61,34],[6,21],[31,13]
        ],
        end : "Checkmate, black loses",
        lose : blackKing ,
        info : "https://en.wikipedia.org/wiki/Scholar%27s_mate",
        gameData :{},
    },
     legalTrap : {
        title: "Légal Trap",
        play : [
            [52,36],[12,28],[61,34],[11,19],[62,45],[2,38],[57,42],[14,22],[45,28],[38,59],[34,13],[4,12],[42,27]
        ],
        end: " Lose the Queen, but win",
        lose : blackKing,
        info : "https://en.wikipedia.org/wiki/L%C3%A9gal_Trap",
        gameData : {
            wPlayer : "Légal",
            bPlayer : "Saint Brie",
            site : "Paris",
            year : 1750,
        },
    },   
}
            
          
!
999px

Console