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.
<!--
This example shows how to use CSS media queries with SVG, and the difference between using a media query on an inline SVG and on an SVG being used as the source of an img element.
Icon designed by: Peter Nowell
-->
<p>This example shows how to use CSS media queries with SVG. This color swatches icon has a small and large scale version. If the SVG is inline with the HTML, media queries detecting viewport width will use the width of the window, like you'd expect. In this example, the media query has been included at the top of the SVG element.
<br><br>
But when the same SVG (containing a media query) is used as the source of an img element, the media query can't detect the width of the window... instead the SVG's viewport detects the dimensions of its container—the img element. <span>Notice how the "img SVG" only responds to the width of the img—not the width of the window, like the inline SVG does.<span></p>
<p class="caption">Inline SVG:</p>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="97" height="60" viewBox="0 0 97 60" version="1.1">
<defs>
<!-- CSS to toggle between "normal-scale" and "large-scale" versions of the icon: -->
<style>
.normal-scale {
display: block;
}
.large-scale {
display: none;
}
@media screen and (min-width:500px) {
.normal-scale {
display: none;
}
.large-scale {
display: block;
}
}
.top-panel,
.mid-panel,
.back-panel {
transform-origin: 48px 50px;
}
.mid-panel {
transform: rotate(27deg);;
}
.back-panel {
transform: rotate(53deg);
}
</style>
</defs>
<g class="normal-scale">
<g class="back-panel">
<path id="back-panel-fill" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961"/>
<rect id="back-swatch-1" fill="#40D68B" x="41" y="6" width="14" height="7"/>
<rect id="back-swatch-2" fill="#41D967" x="41" y="14" width="14" height="7"/>
<rect id="back-swatch-3" fill="#59DB4B" x="41" y="22" width="14" height="7"/>
<rect id="back-swatch-4" fill="#7DDE45" x="41" y="30" width="14" height="7"/>
<rect id="back-swatch-5" fill="#A6E647" x="41" y="38" width="14" height="7"/>
</g>
<g class="mid-panel">
<path id="mid-panel-fill" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961"/>
<rect id="mid-swatch-1" fill="#0BCDD4" x="41" y="6" width="14" height="7"/>
<rect id="mid-swatch-2" fill="#20D6CA" x="41" y="14" width="14" height="7"/>
<rect id="mid-swatch-3" fill="#23DEBF" x="41" y="22" width="14" height="7"/>
<rect id="mid-swatch-4" fill="#33E8B2" x="41" y="30" width="14" height="7"/>
<rect id="mid-swatch-5" fill="#55F2B3" x="41" y="38" width="14" height="7"/>
</g>
<g class="top-panel">
<path id="top-panel" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961"/>
<rect id="top-swatch-1" fill="#31A0F7" x="41" y="6" width="14" height="7"/>
<rect id="top-swatch-2" fill="#31B2F8" x="41" y="14" width="14" height="7"/>
<rect id="top-swatch-3" fill="#31C3F8" x="41" y="22" width="14" height="7"/>
<rect id="top-swatch-4" fill="#31D3F8" x="41" y="30" width="14" height="7"/>
<rect id="top-swatch-5" fill="#31E4F8" x="41" y="38" width="14" height="7"/>
</g>
<circle class="pin" fill="#565961" cx="48" cy="50" r="2"/>
</g>
<g class="large-scale">
<g class="back-panel">
<path id="back-panel-fill" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961" stroke-width=".5"/>
<rect id="back-swatch-1" fill="#40D68B" x="40.75" y="6" width="14.5" height="7.5"/>
<rect id="back-swatch-2" fill="#41D967" x="40.75" y="14" width="14.5" height="7.5"/>
<rect id="back-swatch-3" fill="#59DB4B" x="40.75" y="22" width="14.5" height="7.5"/>
<rect id="back-swatch-4" fill="#7DDE45" x="40.75" y="30" width="14.5" height="7.5"/>
<rect id="back-swatch-5" fill="#A6E647" x="40.75" y="38" width="14.5" height="7.5"/>
</g>
<g class="mid-panel">
<path id="mid-panel-fill" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961" stroke-width=".5"/>
<rect id="mid-swatch-1" fill="#0BCDD4" x="40.75" y="6" width="14.5" height="7.5"/>
<rect id="mid-swatch-2" fill="#20D6CA" x="40.75" y="14" width="14.5" height="7.5"/>
<rect id="mid-swatch-3" fill="#23DEBF" x="40.75" y="22" width="14.5" height="7.5"/>
<rect id="mid-swatch-4" fill="#33E8B2" x="40.75" y="30" width="14.5" height="7.5"/>
<rect id="mid-swatch-5" fill="#55F2B3" x="40.75" y="38" width="14.5" height="7.5"/>
</g>
<g class="top-panel">
<path id="top-panel" d="M40.5 5.01C40.5 3.62 41.63 2.5 42.99 2.5L53.01 2.5C54.38 2.5 55.5 3.62 55.5 5.01L55.5 50C55.5 54.14 52.13 57.5 48 57.5 43.86 57.5 40.5 54.14 40.5 50L40.5 5.01 40.5 5.01Z" fill="#FFFFFF" stroke="#565961" stroke-width=".5"/>
<rect id="top-swatch-1" fill="#31A0F7" x="40.75" y="6" width="14.5" height="7.5"/>
<rect id="top-swatch-2" fill="#31B2F8" x="40.75" y="14" width="14.5" height="7.5"/>
<rect id="top-swatch-3" fill="#31C3F8" x="40.75" y="22" width="14.5" height="7.5"/>
<rect id="top-swatch-4" fill="#31D3F8" x="40.75" y="30" width="14.5" height="7.5"/>
<rect id="top-swatch-5" fill="#31E4F8" x="40.75" y="38" width="14.5" height="7.5"/>
</g>
<circle class="pin" fill="none" stroke="#565961" stroke-width=".5" cx="48" cy="50" r="1.5"/>
</g>
</svg>
<p class="caption">Img with SVG src:</p>
<img alt="icon" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/44800/1-dynamic-icon.svg" />
<div class="scale-button">Change the img width to </div>
svg,
img {
display: block;
margin: 10px 0;
border: 1px lightgray solid;
}
body {
max-width: 650px;
padding: 0 10px;
margin: 50px auto 100px auto;
}
/* Rotate Middle & Back Panels */
.top-panel,
.mid-panel,
.back-panel {
transform-origin: 48px 50px;
}
.mid-panel {
transform: rotate(27deg);;
}
.back-panel {
transform: rotate(53deg);
}
/* Captions, Zoom Button, Zooming */
body {
font-family: Avenir, sans-serif;
color: #404248;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.caption {
margin: 30px 0 0 0;
}
p span {
font-weight: 600;
}
img {
margin-bottom: 320px;
}
.scaled img {
width: 500px;
margin-bottom: 0;
}
.scale-button {
position: fixed;
bottom: 20px;
background: white;
cursor: pointer;
padding: 5px 15px;
border: 1px solid #3279FD;
border-radius: 4px;
color: #3074F3;
}
.scale-button:after {
content: "500px";
}
.scaled .scale-button:after {
content: "original size";
}
// Event Listener for Zoom Button
$('.scale-button').click( changeSize );
// Function to zoom in or out
function changeSize() {
if( $('html').hasClass('scaled') ) {
$('html').removeClass('scaled');
}else{
$('html').addClass('scaled');
};
};
Also see: Tab Triggers