Skip to content

Instantly share code, notes, and snippets.

@jdlehman
Created August 13, 2014 15:37
Show Gist options
  • Save jdlehman/d93d228bb5b0913d2a8a to your computer and use it in GitHub Desktop.
Save jdlehman/d93d228bb5b0913d2a8a to your computer and use it in GitHub Desktop.
A Pen by Jonathan Lehman.
<div class="board">
<div class="card">1</div>
<div class="card">1</div>
<div class="card">2</div>
<div class="card">2</div>
<div class="card">3</div>
<div class="card">3</div>
<div class="card">4</div>
<div class="card">4</div>
<div class="card">5</div>
<div class="card">5</div>
<div class="card">6</div>
<div class="card">6</div>
<div class="card">7</div>
<div class="card">7</div>
<div class="card">8</div>
<div class="card">8</div>
<div class="card">9</div>
<div class="card">9</div>
</div>
$(".card").on("click", function() {
if ($(".board").hasClass("locked")) { return }
$(this).toggleClass("selected")
var selected = $(".selected")
if (selected.length == 2) {
if (selected.first().html() == selected.last().html()) {
selected.addClass("matched")
}
$(".board").addClass("locked")
setTimeout(function() {
selected.removeClass("selected")
$(".board").removeClass("locked")
}, 1000)
}
if ($(".card").not(".matched").length == 0) {
alert("winner!")
}
})
* {
box-sizing: border-box;
}
.board {
width: 100%;
margin: auto 0;
display: flex;
flex-direction: row;
flex-wrap: wrap;
justify-content: left;
align-content: center;
align-items: center;
}
.card {
margin: 1rem;
padding: 1rem;
font-size: 3rem;
text-align: center;
/* flex-grow: 1; */
flex-basis: 150px;
height: 150px;
background-color: red;
color: red;
}
.selected {
color: white;
}
.matched {
background-color: green;
color: white;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment