HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!DOCTYPE html>
<html lang="tr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Animals</title>
<script src="javascript.js"></script>
<link rel="stylesheet" href="style.css">
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&subset=latin-ext" rel="stylesheet">
</head>
<body>
<div class="cards-container">
<div class="left-side">
<div class="box">
<span class="text">Zaman</span>
<div class="time">
</div>
</div>
<div class="box">
<span class="text">Level</span>
<div class="level">
1/4
</div>
</div>
<div class="box">
<span class="text">Puan</span>
<div class="score">
0
</div>
</div>
</div>
<div class="right-side">
<div class="flex-cards">
</div>
</div>
</div>
</body>
</html>
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
body {
font-family: Roboto;
}
img {
max-width: 100%;
max-height: 100%
}
.cards-container {
padding: 0 15px;
width: 1140px;
margin: auto;
max-width: 100%;
display: flex;
flex-wrap: wrap;
align-items: center;
}
.cards-container .flex-cards {
margin: 0 -15px;
display: flex;
flex-wrap: wrap;
justify-content: center;
perspective: 1000px;
}
.cards-container .card {
width: calc(25% - 30px);
height: 200px;
margin: 15px;
position: relative;
cursor: pointer;
border-radius: 9px;
overflow: hidden;
box-shadow: 3px 3px 5px rgba(0,0,0,.1);
transform-style: preserve-3d;
transition: all .5s
}
.cards-container .card .front, .cards-container .card .back {
background: #F44336;
position: absolute;
padding: 20px;
width: 100%;
height: 100%;
backface-visibility: hidden;
}
.cards-container .card .back {
transform: rotateY(180deg);
}
.cards-container .card .point {
color: #FFF;
position: absolute;
left: 50%;
top: 50%;
backface-visibility: inherit;
transform: rotateY(180deg) translate(-50%, -50%);
font-size: 36px;
transform-origin: left;
opacity: 1;
transition: all 300ms;
}
.cards-container .card.matched .point {
opacity: 0;
transition: all 300ms;
transition-delay: 1500ms;
}
.cards-container .card.clicked, .cards-container .card.matched {
pointer-events: none;
transform: rotateY(180deg);
}
.cards-container .card.clicked .back {
backface-visibility: inherit;
}
.left-side {
width: 20%;
padding: 0 15px
}
.left-side .box {
box-shadow: 0 2px 8px 0px rgba(0,0,0,.2);
padding: 15px;
margin-bottom: 30px;
}
.left-side .box .text {
font-weight: 700;
text-transform: uppercase;
display: block;
}
.left-side .box div {
padding: 5px 10px;
font-size: 23px
}
.left-side .box:first-child div {
background: linear-gradient(#ffffff, #ffdf81)
}
.left-side .box:nth-child(2) div {
background: linear-gradient(#ffffff, #9ef4ff)
}
.left-side .box:nth-child(3) div {
background: linear-gradient(#ffffff, #f5ff91)
}
.left-side .box:last-child {
margin-bottom: 0
}
.right-side {
width: 80%;
padding: 0 15px;
position: relative;
}
.game-over, .game-win {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
.game-over .message, .game-win .message {
font-size: 40px;
color: #FFF;
text-transform: uppercase;
margin-bottom: 20px;
text-align: center;
text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}
.game-over button, .game-win button {
padding: 15px 55px;
text-transform: uppercase;
background: linear-gradient(magenta, purple);
border: 3px solid #FFF;
box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.3);
font-size: 22px;
color: #FFF;
cursor: pointer;
outline: none;
border-radius: 5px;
}
@keyframes fadeInUp{
0% {
opacity:0;
transform:translate3d(0,100%,0)
}
to {
opacity:1;
transform:none
}
}
//timer
//level
//score
//sound click
var url = 'http://fkonyali.com/animals/',
cardsC = document.getElementsByClassName('flex-cards'),
card = document.getElementsByClassName('card'),
cardClick = document.getElementsByClassName('clicked'),
cardMatch = document.getElementsByClassName('matched'),
score = document.getElementsByClassName('score'),
level = document.getElementsByClassName('level'),
wi_level = 1,
right_side = document.getElementsByClassName('right-side'),
level1cards = ['dog', 'cat', 'bear', 'elephant', 'dog', 'cat', 'bear', 'elephant'],
level2cards = ['owl', 'lion', 'monkey', 'fish', 'chicken', 'rabbit', 'owl', 'lion', 'monkey', 'fish', 'chicken', 'rabbit'],
level3cards = ['panda', 'tiger', 'unicorn', 'zebra', 'bat', 'giraffe', 'animal', 'chameleon','panda', 'tiger', 'unicorn', 'zebra', 'bat', 'giraffe', 'animal', 'chameleon'],
level4cards = ['cheetah', 'crocodile', 'fox', 'goat', 'koala', 'narwhal', 'otter', 'sheep', 'dog', 'panda', 'cheetah', 'crocodile', 'fox', 'goat', 'koala', 'narwhal', 'otter', 'sheep', 'dog', 'panda'];
function shuffle(array) {
var currentIndex = array.length,
temporaryValue,
randomIndex;
while(0 != currentIndex) {
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var level1cards_mix = shuffle(level1cards),
level2cards_mix = shuffle(level2cards),
level3cards_mix = shuffle(level3cards),
level4cards_mix = shuffle(level4cards);
function innerItems(x,y,z) {
for(i=0; i<y.length; i++) {
x[0].innerHTML +=
"<div class='card' data-img='"+btoa(z[i])+"'>"+
"<div class='front'>"+
"</div>"+
"<div class='back'>"+
"</div>"+
"<div class='point'>"+
"</div>"+
"</div>";
}
innerItems_click(y);
}
function innerItems_click(y) {
for(a=0; a<y.length; a++) {
card[a].addEventListener("click", click_cards);
}
}
var hasClickCard = false,
clickable = false,
firstCard, secondCard, point=0, totalPoint=0;
function click_cards(e) {
var attr = atob(this.getAttribute("data-img"));
if(clickable) return;
this.classList.add('clicked');
this.getElementsByClassName('back')[0].innerHTML = "<img src='"+url+attr+".svg' alt='"+attr+"' />";
if(!hasClickCard) {
//first click
hasClickCard = true;
firstCard = this;
firstCardAttr = firstCard.getAttribute('data-img');
}else {
//second click
hasClickCard = false;
secondCard = this;
secondCardAttr = secondCard.getAttribute('data-img');
checkForMatch();
}
}
var timer_circle;
function startTimer(duration, display) {
var timer = duration, minutes, seconds;
timer_circle = setInterval(function () {
minutes = parseInt(timer / 60, 10)
seconds = parseInt(timer % 60, 10);
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds;
//if timer zero is game over
if(timer == 0) {
clearInterval(timer_circle);
right_side[0].innerHTML += "<div class='game-over'>"+
"<div class='message'>Kaybettin!</div>"+
"<button id='play-again'>Tekrar Oyna</button>"+
"</div>"
var playAgain_btn = document.getElementById('play-again');
playAgain_btn.addEventListener('click', play_again);
}else {
if (--timer < 0) {
timer = duration;
}
}
}, 1000);
}
function checkForMatch() {
var lastMatch_Cards = cardMatch.length;
console.log(lastMatch_Cards);
//if match
if(firstCardAttr === secondCardAttr) {
disabledCards();
firstCard.classList.add('matched');
secondCard.classList.add('matched');
//point
point +=100;
totalPoint +=point * 2;
score[0].innerHTML = totalPoint;
firstCard.getElementsByClassName('point')[0].innerHTML = "+"+point;
secondCard.getElementsByClassName('point')[0].innerHTML = "+"+point;
if(wi_level == 1 && lastMatch_Cards == 6) {
//game-win
clearInterval(timer_circle);
right_side[0].innerHTML += "<div class='game-win'>"+
"<div class='message'>Kazandın!</div>"+
"<button id='second-level'>Sonraki Seviye</button>"+
"</div>"
var secondLevel_btn = document.getElementById('second-level');
secondLevel_btn.addEventListener('click', secondLevel);
}else if(wi_level == 2 && lastMatch_Cards == 10) {
//game-win
clearInterval(timer_circle);
right_side[0].innerHTML += "<div class='game-win'>"+
"<div class='message'>Kazandın!</div>"+
"<button id='third-level'>Sonraki Seviye</button>"+
"</div>"
var thirdLevel_btn = document.getElementById('third-level');
thirdLevel_btn.addEventListener('click', thirdLevel);
}else if(wi_level == 3 && lastMatch_Cards == 14) {
//game-win
clearInterval(timer_circle);
right_side[0].innerHTML += "<div class='game-win'>"+
"<div class='message'>Kazandın!</div>"+
"<button id='fourth-level'>Sonraki Seviye</button>"+
"</div>"
var fourthLevel_btn = document.getElementById('fourth-level');
fourthLevel_btn.addEventListener('click', fourthLevel);
}else if(wi_level == 4 && lastMatch_Cards == 18){
//game-win
clearInterval(timer_circle);
right_side[0].innerHTML += "<div class='game-win'>"+
"<div class='message'>Oyun bitti. Kazandın!</div>"+
"<button id='play-again'>Tekrar Baştan Oyna</button>"+
"</div>";
wi_level = 1;
var playAgain_btn = document.getElementById('play-again');
playAgain_btn.addEventListener('click', play_again);
}
}else {
unClickCards();
//point
point = 0;
}
}
function secondLevel() {
wi_level = 2;
point = 0;
right_side[0].innerHTML = "";
level[0].innerHTML = "2/4";
var level2cards_minutes = 85,
display = document.querySelector('.time');
startTimer(level2cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level2cards,level2cards_mix);
}
function thirdLevel() {
wi_level = 3;
point = 0;
right_side[0].innerHTML = "";
level[0].innerHTML = "3/4";
var level3cards_minutes = 150,
display = document.querySelector('.time');
startTimer(level3cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level3cards,level3cards_mix);
}
function fourthLevel() {
wi_level = 4;
point = 0;
right_side[0].innerHTML = "";
level[0].innerHTML = "4/4";
var level4cards_minutes = 210,
display = document.querySelector('.time');
startTimer(level4cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level4cards,level4cards_mix);
}
console.log(wi_level);
function disabledCards() {
//is match
firstCard.removeEventListener('click', click_cards);
secondCard.removeEventListener('click', click_cards);
}
function unClickCards() {
clickable = true;
setTimeout(function(){
firstCard.classList.remove('clicked');
secondCard.classList.remove('clicked');
clickable = false;
},1500);
}
function play_again() {
var display = document.querySelector('.time');
point = 0;
level[0].innerHTML = "1/4";
score[0].innerHTML = "0";
if(wi_level == 1) {
var level1cards_minutes = 38;
startTimer(level1cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level1cards,level1cards_mix);
}else if(wi_level == 2) {
var level2cards_minutes = 85;
startTimer(level2cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level2cards,level2cards_mix);
}else if(wi_level == 3) {
var level3cards_minutes = 150;
startTimer(level3cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level3cards,level3cards_mix);
}else {
var level4cards_minutes = 210;
startTimer(level4cards_minutes, display);
right_side[0].innerHTML = "<div class='flex-cards'></div>";
innerItems(cardsC,level4cards,level4cards_mix);
}
}
window.onload = function() {
innerItems(cardsC,level1cards,level1cards_mix);
var level1cards_minutes = 38,
display = document.querySelector('.time');
startTimer(level1cards_minutes, display);
}
Also see: Tab Triggers