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.
<body>
<div id='field'>
<header>
<p> Click the flowers, but avoid the wasps!</p>
<h2>flowers:<span class='flowers'>0</span></h1>
<h2>lives:<span class='lives'>5</span></h1>
</header>
<img id='bee' src='http://clipartix.com/wp-content/uploads/2016/04/Cute-bee-clipart-free-clipart-images-2.png' alt='bee'>
<div class='flowers'>
<div id='flower1' class='flower'></div>
<div id='flower2' class='flower'></div>
<div id='flower3' class='flower'></div>
</div>
<div class='enemies'>
<div class='wasp wasp1'>🐝</div>
<div class='wasp wasp2'>🐝</div>
<div class='wasp wasp3'>🐝</div>
<div class='wasp wasp4'>🐝</div>
<div id='bigWasp' class='wasp bigWasp'></div>
</div>
<h2 id='konamiEgg'></h2>
<footer>
<h2>Level<span class="level">1</span></h2>
<p>Code and design by Amie Everett © 2017
<a href='https://twitter.com/AmieEverett_'target='_blank'><i class='fa fa-twitter' aria-hidden='true'></i></a>
<a href='https://www.linkedin.com/in/amie-everett-0573a0144/' target='_blank'><i class="fa fa-linkedin" aria-hidden="true"></i></a>
</p>
</footer>
<aside>
<h1>Game Over 🙁</h1>
<p>You made it to level <span class='level'>1</span>!</p>
<div>
<a class='tweet' href='' target='_blank'>Tweet your level</a>
<button>Play again</button>
</div>
</aside>
</div>
<svg width='0' height='0'>
<defs>
<clipPath id='flowerClip'>
<circle cx='30' cy='44' r='20'/>
<circle cx='76' cy='52' r='20'/>
<circle cx='70' cy='21' r='20'/>
<circle cx='40' cy='20' r='20'/>
<circle cx='50' cy='61' r='20'/>
</clipPath>
</defs>
</svg>
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js'></script>
<script type="text/javascript" src="https://cdn.rawgit.com/mikeflynn/egg.js/master/egg.min.js"></script>
<script src='https://use.fontawesome.com/863f28bd20.js'></script>
<script src='scripts/script.js'></script>
</body>
</html>
/* setup styles */
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section, summary {
display: block; }
audio, canvas, video {
display: inline-block; }
audio:not([controls]) {
display: none;
height: 0; }
[hidden] {
display: none; }
html {
font-family: sans-serif;
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%; }
a:focus {
outline: thin dotted; }
a:active, a:hover {
outline: 0; }
h1 {
font-size: 2em;
text-transform: uppercase;}
abbr[title] {
border-bottom: 1px dotted; }
b, strong {
font-weight: 700; }
dfn {
font-style: italic; }
mark {
background: #ff0;
color: #000; }
code, kbd, pre, samp {
font-family: monospace, serif;
font-size: 1em; }
pre {
white-space: pre-wrap;
word-wrap: break-word; }
q {
quotes: \201C \201D \2018 \2019; }
small {
font-size: 80%; }
sub, sup {
font-size: 75%;
line-height: 0;
position: relative;
vertical-align: baseline; }
sup {
top: -.5em; }
sub {
bottom: -.25em; }
img {
border: 0; }
svg:not(:root) {
overflow: hidden; }
fieldset {
border: 1px solid silver;
margin: 0 2px;
padding: .35em .625em .75em; }
button, input, select, textarea {
font-family: inherit;
font-size: 100%;
margin: 0; }
button, input {
line-height: normal; }
button, html input[type=button], input[type=reset], input[type=submit] {
-webkit-appearance: button;
cursor: pointer; }
button[disabled], input[disabled] {
cursor: default; }
input[type=checkbox], input[type=radio] {
-webkit-box-sizing: border-box;
box-sizing: border-box;
padding: 0; }
input[type=search] {
-webkit-appearance: textfield;
-moz-box-sizing: content-box;
-webkit-box-sizing: content-box;
box-sizing: content-box; }
input[type=search]::-webkit-search-cancel-button, input[type=search]::-webkit-search-decoration {
-webkit-appearance: none; }
textarea {
overflow: auto;
vertical-align: top; }
table {
border-collapse: collapse;
border-spacing: 0; }
body, figure {
margin: 0; }
legend, button::-moz-focus-inner, input::-moz-focus-inner {
border: 0;
padding: 0; }
.clearfix:after {
visibility: hidden;
display: block;
font-size: 0;
content: '';
clear: both;
height: 0; }
* {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box; }
/* global styles */
@-webkit-keyframes wasp {
0% {
top: 20px; }
10%, 30%, 50%, 70%, 90% {
margin-left: 10%; }
50% {
top: 82%; }
20%, 40%, 60%, 80% {
margin-left: 30%; }
100% {
top: 20px; } }
@keyframes wasp {
0% {
top: 20px; }
10%, 30%, 50%, 70%, 90% {
margin-left: 10%; }
50% {
top: 75%; }
20%, 40%, 60%, 80% {
margin-left: 30%; }
100% {
top: 20px; } }
@-webkit-keyframes bigWasp {
0% {
top: 20%; }
25% {
top: 50%; }
10%, 30%, 50%, 70%, 90% {
left: 20%; }
20%, 40%, 60%, 80% {
left: 80%; }
75% {
top: 75%; }
100% {
top: 20%; } }
@keyframes bigWasp {
0% {
top: 20%; }
25% {
top: 50%; }
10%, 30%, 50%, 70%, 90% {
left: 20%; }
20%, 40%, 60%, 80% {
left: 80%; }
75% {
top: 75%; }
100% {
top: 20%; } }
body {
margin: 0;
cursor: none;
font-family: 'Josefin Sans', sans-serif; }
img {
position: absolute;
height: 50px;
width: 50px;
z-index: 20; }
#field {
/* cursor: none; */
height: calc(100vh);
/* background-color: rgb(54, 163, 99); */
background-image: -webkit-gradient(linear, left top, left bottom, from(rgba(68, 247, 68, 0.3)), to(rgba(0, 0, 0, 0.6))), url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2ZsO3qgWlDHeyCAQEiQwvf8f_uht6hMigFtHVhfZj9rguVyyGjg");
background-image: -webkit-linear-gradient(rgba(68, 247, 68, 0.3), rgba(0, 0, 0, 0.6)), field = url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2ZsO3qgWlDHeyCAQEiQwvf8f_uht6hMigFtHVhfZj9rguVyyGjg");
background-image: -o-linear-gradient(rgba(68, 247, 68, 0.4), rgba(0, 0, 0, 0.4)), field = url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2ZsO3qgWlDHeyCAQEiQwvf8f_uht6hMigFtHVhfZj9rguVyyGjg");
align-items: center;background-image: linear-gradient(rgba(68, 247, 68, 0.4), rgba(0, 0, 0, 0.4)), field = url("https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcS2ZsO3qgWlDHeyCAQEiQwvf8f_uht6hMigFtHVhfZj9rguVyyGjg");
background-repeat: no-repeat;
background-size: cover;
margin: 0;
width: 100%;
position: absolute; }
.flower {
position: absolute;
height: 100px;
width: 100px;
background: #f76e44;
-webkit-clip-path: polygon(50% 0%, 77% 28%, 100% 0, 94% 78%, 68% 100%, 32% 100%, 6% 78%, 0 0, 26% 27%);
clip-path: url(#flowerClip);
top: 300px;
left: 400px; }
#flower1 {
top: 300px;
left: 100px;
background: #b700ff;
/* color: rgb(227, 252, 0); */ }
#flower2 {
top: 200px;
left: 300px;
background: #fafa8f;
/* background: red; */ }
#flower3 {
top: 100px;
left: 600px;
/* background: blue */ }
.flower:hover {
/* background: lighten(); */
/* background: rgba(254, 255, 255, 0.767); */
-webkit-filter: brightness(85%);
filter: brightness(85%); }
.wasp {
position: absolute;
z-index: 30;
font-size: 4rem;
-webkit-animation: wasp 5s forwards ease-in-out infinite;
animation: wasp 5s forwards ease-in-out infinite; }
.wasp1 {
left: 5%;
-webkit-animation-duration: 8s;
animation-duration: 8s; }
.wasp2 {
left: 20%;
-webkit-animation-duration: 10s;
animation-duration: 10s; }
.wasp3 {
left: 40%;
-webkit-animation-duration: 4s;
animation-duration: 4s; }
.wasp4 {
left: 60%;
-webkit-animation-duration: 6s;
animation-duration: 6s; }
.bigWasp {
background-image: url(https://freeclipartimage.com//storage/upload/wasp-clipart/wasp-clipart-1.png);;
background-repeat: no-repeat;
background-size: cover;
min-height: 100px;
min-width: 100px;
left: 50%;
top: 50%;
position: absolute;
/* z-index: 30; */
font-size: 5rem;
-webkit-animation: bigWasp 20s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
animation: bigWasp 20s forwards cubic-bezier(0.25, 0.46, 0.45, 0.94) infinite;
/* animation-timing-function: cubic-bezier(0.25, 0.46, 0.45, 0.94); */
/* animation-duration: 20s; */ }
/* header styles */
header, footer {
margin: 10px 35px;
border: 3px solid transparent;
padding: 10px;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: justify;
-webkit-justify-content: space-between;
-ms-flex-pack: justify;
justify-content: space-between;
-webkit-align-content: center;
-ms-flex-line-pack: center;
align-items: center;
z-index: 50; }
header, footer, aside {
color: white;
background: rgba(30, 110, 30, 0.671);
text-shadow: 2px 2px 5px #001f08; }
p {
margin: 0; }
h2 {
margin: 0;
text-transform: uppercase; }
span {
color: #f76e44;
margin-left: 10px;
font-weight: 700; }
.flashRed {
border: 3px solid rgba(247, 110, 68, 0.705);
}
/* footer styles */
#konamiEgg {
color: red;
}
footer {
position: absolute;
bottom: 10px;
width: calc(100% - 70px); }
a {
color: white; }
aside {
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-orient: vertical;
-webkit-box-direction: normal;
-webkit-flex-direction: column;
-ms-flex-direction: column;
flex-direction: column;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
cursor: pointer;
background: rgba(16, 85, 16, 0.671);
text-align: center;
width: 100%;
height: 100vh;
position: fixed;
z-index: 50;
bottom: -100vh;
-webkit-transition: all 0.5s;
-o-transition: all 0.5s;
transition: all 0.5s; }
aside h1 {
font-size: 4rem;
margin-top: 0; }
aside p {
font-size: 2rem;
margin-bottom: 50px; }
aside a, aside button {
border: none;
text-decoration: none;
text-shadow: 2px 2px 5px #001f08;
padding: 20px;
background: #5c0080;
color: white;
font-size: 1.1rem;
margin: 0 3px;
border-radius: 50px;
border: 2px solid rgb(247, 110, 68);}
aside div {
-webkit-box-orient: horizontal;
-webkit-box-direction: normal;
-webkit-flex-direction: row;
-ms-flex-direction: row;
flex-direction: row;
-webkit-justify-content: space-around;
-ms-flex-pack: distribute;
justify-content: space-around;
margin: 0px 50px 50px 50px; }
beeGame = {};
beeGame.init = function() {
beeGame.flowerCount = 0;
beeGame.lifeCount = 5;
beeGame.level = 1;
beeGame.growFlowers('flower1');
beeGame.growFlowers('flower2');
beeGame.growFlowers('flower3');
beeGame.flowerClick();
beeGame.waspHover();
beeGame.mouseMove();
beeGame.restart();
beeGame.flashRed('footer');
document.getElementById('field').onmousemove = beeGame.mouseMove;
beeGame.bigWasp = document.getElementById('bigWasp');
beeGame.animationDuration = 20;
};
beeGame.mouseMove = function(mouseMovement) {
// when the mouse moves, set xPosition and yPosition to the x and y of the cursor,
// then assign those x and y to the bee in the css file (position absolute, use top and left)
const bee = document.getElementById('bee');
let xPosition;
let yPosition;
if (mouseMovement) {
xPosition = mouseMovement.pageX;
yPosition = mouseMovement.pageY;
bee.style.top = yPosition + 1 + 'px';
// added 1 pixel to get the bee off of the cursor itself so you're clicking on what you want to click on not the bee image
bee.style.left = xPosition + 'px';
};
};
beeGame.growFlowers= function(flowerId) {
// takes a flowerId, gets that element from the DOM and changes it's position to a new random position
const flower = document.getElementById(flowerId);
let randomX = Math.floor(Math.random() * 80) + 5;
let randomY = Math.floor(Math.random() * 70) + 10;
flower.style.top = randomY + 'vh';
flower.style.left = randomX + '%';
};
beeGame.growNewFlower = function (flowerArray) {
// takes in two arrays representing the rgb values,
// then grows a brand new flower and add it to the html
// const red
};
beeGame.flowerClick = function() {
$('.flower').on('click', function () {
// when user clicks a flower, add one to the flower count (a.k.a score), get rid of that flower and grow a new flower
beeGame.flowerCount += 1;
if (beeGame.flowerCount % 5 === 0){
beeGame.level += 1;
beeGame.flashRed('footer');
beeGame.enemyMove();
// $('span.level').text(beeGame.level);
beeGame.updateSpan('.level', beeGame.level);
}
// $('span.flowers').text(beeGame.flowerCount);
beeGame.updateSpan('.flowers', beeGame.flowerCount);
let clickedId = $(this).attr('id');
return (beeGame.growFlowers(clickedId));
});
};
beeGame.waspHover = function() {
$('.wasp').hover(function () {
// when user clicks a flower, add one to the flower count (a.k.a score), get rid of that flower and grow a new flower
beeGame.lifeCount -= 1;
beeGame.flashRed('header');
// $('span.lives').text(beeGame.lifeCount);
beeGame.updateSpan('.lives', beeGame.lifeCount);
if (beeGame.lifeCount <= 0) {
$('a.tweet').attr('href', `https://twitter.com/intent/tweet?text=I made it to level ${beeGame.level} in @AmieEverett_'s Bee Game! 🐝`);
// $('span.level').text(beeGame.level);
beeGame.updateSpan('.level', beeGame.level);
$('aside').css({
'bottom': '0',
});
}
});
};
beeGame.enemyMove = function() {
// makes enemy movement faster and more random to increase difficulty
console.log(beeGame.animationDuration,' seconds');
const bezier1 = Math.random();
const bezier2 = Math.random();
const bezier3 = Math.random();
const cubicBezier = `cubic-bezier(${bezier1}, ${bezier2}, ${bezier3}, 1)`;
if (beeGame.animationDuration > 5) {
beeGame.animationDuration -= 5;
} else {
for (i=1; i<=4; i++){
const newSpeed = Math.floor(Math.random()*5)+1;
// console.log($('.wasp')[i]);
// console.log($(`.wasp${i}`));
$(`.wasp${i}`).css({
'animation-duration': `${newSpeed}s`,
'animation-timing-function': `${cubicBezier}`
});
}
}
$('.bigWasp').css({
'animation-duration': `${beeGame.animationDuration}s`,
'animation-timing-function': `${cubicBezier}`
});
};
beeGame.flashRed = function(redElement) {
$(redElement).addClass('flashRed');
setTimeout(function() {
$(redElement).removeClass('flashRed');
}, 1000);
};
beeGame.restart = function(){
$('button').on('click', function () {
window.location = '';
});
};
beeGame.updateSpan = function(spanClass, updatedData) {
$('span' + spanClass).text(updatedData);
}
beeGame.konamiEgg = new Egg();
beeGame.konamiEgg.addCode('up,up,down,down,left,right,left,right,b,a', function () {
jQuery('#konamiEgg').text('Easter egg found!');
beeGame.level = 10;
beeGame.lifeCount = 10;
beeGame.updateSpan('.level', beeGame.level);
beeGame.updateSpan('.lives', beeGame.lifeCount);
beeGame.flashRed('header');
beeGame.flashRed('footer');
window.setTimeout(function () { jQuery('#konamiEgg').hide(); }, 1000);
})
.addHook(function () {
console.log('Easter egg found!');
}).listen();
$(beeGame.init());
Also see: Tab Triggers