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 Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
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.
<h1>Slot Machine</h1>
<div class="container">
<div class="slot">
<div class="base-machine">
<div class="base-frame">
<div class="slots">
<ul class="list list1">
<li>$4</li>
<li>$1</li>
<li>$65</li>
<li>$21</li>
<li>$0</li>
<li>$8</li>
<li>$32</li>
<li>$45</li>
<li>$56</li>
<li>$3</li>
</ul>
</div>
<div class="slots">
<ul class="list list2">
<li>$4</li>
<li>$1</li>
<li>$65</li>
<li>$21</li>
<li>$0</li>
<li>$8</li>
<li>$32</li>
<li>$45</li>
<li>$56</li>
<li>$3</li>
</ul>
</div>
<div class="slots">
<ul class="list list3">
<li>$4</li>
<li>$1</li>
<li>$65</li>
<li>$21</li>
<li>$0</li>
<li>$8</li>
<li>$32</li>
<li>$45</li>
<li>$56</li>
<li>$3</li>
</ul>
</div>
<div class="trapezoid">
<div class="edge"></div>
</div>
</div>
</div>
<div id="slot-trigger">
<svg id="trigger" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="35" height="143.6" viewBox="0 0 35 143.6">
<defs>
<linearGradient id="linear-gradient" x1="6.21" y1="143.63" x2="6.21" y2="67.37" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#515151"/>
<stop offset="0.21" stop-color="#989898"/>
<stop offset="0.51" stop-color="#e3e3e3"/>
<stop offset="0.82" stop-color="#949494"/>
<stop offset="1" stop-color="#444"/>
</linearGradient>
<linearGradient id="linear-gradient-2" x1="23.71" y1="127.98" x2="23.71" y2="83.01" xlink:href="#linear-gradient"/>
<linearGradient id="linear-gradient-3" x1="20.46" y1="55.66" x2="25.41" y2="55.66" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#6b6b6b"/>
<stop offset="1" stop-color="#454545"/>
</linearGradient>
<radialGradient id="radial-gradient" cx="23.05" cy="12.33" fx="31.426365772510508" r="12.04" gradientTransform="translate(1.5 -0.3) scale(0.93 0.93)" gradientUnits="userSpaceOnUse">
<stop offset="0" stop-color="#e47f7f"/>
<stop offset="0.68" stop-color="#ae292a"/>
</radialGradient>
</defs>
<path id="ring1" d="M0,67.4H7.3a5.1,5.1,0,0,1,5.1,5.1v66.1a5.1,5.1,0,0,1-5.1,5.1H0a0,0,0,0,1,0,0V67.4A0,0,0,0,1,0,67.4Z" fill="url(#linear-gradient)"/>
<path id="ring2" d="M12.4,83H29.7A5.3,5.3,0,0,1,35,88.3v34.4a5.3,5.3,0,0,1-5.3,5.3H12.4a0,0,0,0,1,0,0V83A0,0,0,0,1,12.4,83Z" fill="url(#linear-gradient-2)"/>
<ellipse id="hole" cx="22.9" cy="88.6" rx="5.9" ry="2.2" fill="#3f3f3f"/>
<rect id="stick" x="20.5" y="22.2" width="5" height="66.88" fill="url(#linear-gradient-3)"/>
<ellipse id="head" cx="22.9" cy="11.3" rx="11.2" ry="11.3" fill="url(#radial-gradient)"/>
</svg>
</div>
</div>
</div>
</div>
/* Chaange the artboard size here */
\:root
--width: 70vw
--height: 60vh
--machine-w: calc(var(--width) * .7)
--machine-h: 266px
@import url('https://fonts.googleapis.com/css?family=Open+Sans:600')
body
font-family: 'Open Sans', sans-serif
font-weight: 600
text-align: center
background: #eff2f7
h1
color: #aaa
margin-top: 3rem
/*.container
display: flex
align-items: center
justify-content: center
width: var(--width)
height: var(--height)
background: #fff
margin: 40px auto
border-radius: 15px
box-shadow: 0px 20px 30px -10px rgba(39, 57, 86, .2) */
.slot
display: flex
align-items: center
justify-content: center
#slot-trigger
cursor: pointer
.base-machine
width: var(--machine-w)
height: var(--machine-h)
background: -webkit-linear-gradient(top, #ff670f 0%,#ff670f 100%)
border-radius: 15px 15px 0 0
display: flex
justify-content: center
align-items: center
box-shadow: inset 0 0px 3px #ffcc99, 0px 10px 30px rgba(0,0,0, .4)
.base-frame
width: calc(var(--machine-w) - 40px)
height: calc(var(--machine-h) - 40px)
background: -webkit-linear-gradient(top, #222 0%,#666 36%,#252525 100%)
opacity: 1
border-radius: 3px
display: flex
justify-content: space-evenly
align-items: center
box-shadow: inset 0 0 7px #000
.slots
width: calc((var(--machine-w) / 3) - 30px)
height: calc(var(--machine-h) - 60px)
background: -webkit-linear-gradient(top, #999 0%,#e8e8e8 15%,#ffffff 50%,#e8e8e8 85%,#999 100%)
box-shadow: 0 0 15px -10px rgba(0, 0, 0, 0.5)
border-radius: 6px
font-size: 2rem
line-height: 2
overflow: hidden
.trapezoid
width: calc(var(--machine-w))
border-bottom: 20px solid #242424
border-left: 20px solid transparent
border-right: 20px solid transparent
position: absolute
margin-top: 280px
display: flex
justify-content: center
.edge
height: 40px
width: calc(var(--machine-w) + 40px)
background: linear-gradient(to bottom, #4c4c4c 0%,#2d2d2d 17%,#2d2d2d 17%,#111111 40%,#3f3f3f 76%,#131313 100%)
position: absolute
margin-top: 20px
border-radius: 0 0 3px 3px
.list
list-style-type: none
padding: 0
margin: .3rem auto
span.list
height: 1em
line-height: 1em
$(document).ready( function(){
var list1 = $('.list1'),
list2 = $('.list2'),
list3 = $('.list3'),
liHeight = $('li').outerHeight(),
btnSpin = $('#slot-trigger'),
head = $('#head'),
stick = $('#stick'),
hole = $('#hole');
function spin() {
var r1 = R(3,8),
r2 = R(1,6),
r3 = R(1,6);
TweenMax.to(list1, 1.3, {y: 0-(liHeight*r1), ease: Elastic.easeInOut.config(6, 0)});
TweenMax.to(list2, 1.3, {y: 0-(liHeight*r2), ease: Elastic.easeInOut.config(6, 0), delay: .1});
TweenMax.to(list3, 1.3, {y: 0-(liHeight*r3), ease: Elastic.easeInOut.config(6, 0), delay: .2});
console.log(r1, r2, r3, liHeight);
}
function slotTriggerMove() {
TweenMax.set([head, stick, hole], {y:0, scale: 1});
TweenMax.to(head, .4, {y: 70, repeat: 1, yoyo: true, ease:Sine.easeIn});
TweenMax.to(stick, .4, {y: 14, scaleY: .3,transformOrigin:"50% 100%", repeat: 1, yoyo: true, ease:Sine.easeIn});
TweenMax.to(hole, .4, {y: 10, scaleY: 2, repeat: 1, yoyo: true, ease:Sine.easeIn});
}
//Generate random spin times
function R(min,max) {
return Math.floor(Math.random() * (max - min) + min);
};
// Button
btnSpin.click(function(){
slotTriggerMove();
spin();
}
);
});
Also see: Tab Triggers