JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.
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.
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.
<span id="ball"></span>
<section>
<span id="moveMe">Animation</span>
</section>
<section>
<div class="transition">Transition</div>
</section>
<section>
<div class="user-img"></div>
</section>
<!--
Common transforms:
transform: scale(2, 0.5);
transform: scaleX(2);
transform: scaleY(0.5);
transform: rotate(0.5turn);
transform: translateZ(2px);
transform: scale3d(2.5, 1.2, 0.3);
transform: scaleZ(0.3);
transform: rotate3d(1, 2.0, 3.0, 10deg);
transform: rotateX(10deg);
transform: rotateY(10deg);
transform: rotateZ(10deg);
transform: perspective(17px);
-->
* {box-sizing: border-box;}
body {
font-family: arial;
background: #444;
color: #ccc;
}
section {
width: 200px;
display: block;
position: absolute;
}
.transition {
border: 5px solid #333;
text-align: center;
height: 5em;
width: 6em;
line-height: 4.5em;
background: #666;
opacity: .5;
margin: 1em 1em 0 15em;
// No commas between transforms
transform: scale(1.2) ; // Transform simply applied
transform-origin: center center;
transition:
line-height .5s,
color .5s,
width .5s,
height .5s,
background .5s,
transform .5s, // Looks at transform property and applies over time
opacity .5s,
ease;
&:hover {
color: #444;
opacity: .5;
background: #ccc;
width: 8em;
height: 8em;
line-height: 7em;
// Something I want the element to do when hovered.
// Without the transition property specifying it over time,
// it would just be applied immediately
transform: rotate(-5deg);
}
}
// Transform triggered with a JS onclick event
#ball{
border: 5px solid #333;
border-radius: 50px;
width: 50px;
height: 50px;
background: #666;
position: absolute;
top: 0;
left: 0;
transition: transform 1s;
}
// CSS Animations: create your animation
// use transforms for positioning, it creates a new
// stacking context and allows the browser to use the GPU
@keyframes play {
0% { transform: translate(50px, 0); opacity: 0; }
25% { transform: translate(100px, 0); }
50% { transform: translate(100px, 50px); opacity: 1;}
75% { transform: translate(100px, 0); }
100% { transform: translate(50px, 0); opacity: 0;}
}
#moveMe {
// call your animation by name
animation: play 2s infinite;
border: 5px solid #333;
background: #666;
padding: 1em;
position: absolute;
}
//-----------------------------------------
// Animating clip-path
.user-img {
transition: clip-path .5s ease, opacity .5s ease;
clip-path: circle(10%);
background-image: url(https://upload.wikimedia.org/wikipedia/commons/7/79/SNG.gif);
background-postition: left -30px top -50px;
background-size: 100%;
background-repeat: no-repeat;
height: 200px;
width: 200px;
margin-left: 23em;
opacity: .2;
&:hover {
clip-path: circle(50%);
opacity: 1;
}
}
var b = document.getElementById('ball');
document.addEventListener('click', function(ev){
b.style.transform = 'translateY('+(ev.clientY-25)+'px)';
b.style.transform += 'translateX('+(ev.clientX-25)+'px)';
},false);
Also see: Tab Triggers