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.
<div class="categories">
<div class="card" data-type="jeans">
<img src="http://placehold.it/400x300/?text=Jeans">
<h3>Amazing deals on jeans</h3>
<button>View all <div class="arrow right"></div></button>
</div>
<div class="card" data-type="hats">
<img src="http://placehold.it/400x300/?text=Hats">
<h3>The perfect hat for you</h3>
<button>View all <div class="arrow right"></div></button>
</div>
<div class="card" data-type="shirts">
<img src="http://placehold.it/400x300/?text=Shirts">
<h3>Shop recommended shirts</h3>
<button>View all <div class="arrow right"></div></button>
</div>
<div class="card" data-type="belts">
<img src="http://placehold.it/400x300/?text=Belts">
<h3>The best belts</h3>
<button>View all <div class="arrow right"></div></button>
</div>
<div class="card" data-type="sweaters">
<img src="http://placehold.it/400x300/?text=Sweaters">
<h3>The hottest sweaters</h3>
<button>View all <div class="arrow right"></div></button>
</div>
<div class="card" data-type="shorts">
<img src="http://placehold.it/400x300/?text=Shorts">
<h3>Shorts of the best fit</h3>
<button>View all <div class="arrow right"></div></button>
</div>
</div>
<div class="horizontal-scroll">
<div class="recommendations">
</div>
</div>
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
* {box-sizing: border-box;}
body {margin: 0; padding: 0; font-family: 'Open Sans', sans-serif; color: #333;}
.categories {
width: 100%;
margin: 20px 0 0;
padding: 0;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
}
.categories::after, .recommendations::after {
content: '';
display: table;
clear: both;
}
.card {
width: 16.6667%;
padding: 20px;
float: left;
text-align: center;
border-right: 1px solid #ccc;
}
.card img {
width: 100%;
height: auto;
}
.card button {
font-size: 18px;
background: #ccc;
padding: 10px 50px 10px 25px;
outline: none;
border: none;
text-transform: uppercase;
font-family: Century Gothic, sans-serif;
border-radius: 2px;
color: #444;
position: relative;
cursor: pointer;
}
.card button .arrow {
width: 10px;
height: 10px;
border-right: 1px solid #444;
border-bottom: 1px solid #444;
transform: rotate(-45deg);
position: absolute;
right: 25px;
top: 16px;
transition: all .2s ease;
}
.card button .arrow::after {
content: '';
display: block;
width: 0;
height: 0;
border-left: 23px solid transparent;
border-right: 23px solid transparent;
border-top: 0 solid transparent;
position: absolute;
left: 0;
transform: rotate(45deg);
top: 8px;
transition: border-top .2s ease;
}
.card button .arrow.down::after {
transform: rotate(-45deg);
border-top: 31px solid #ccc;
}
.categories .card button .arrow.down {
transform: rotate(45deg);
}
.horizontal-scroll {
width: 100%;
overflow-x: hidden;
position: relative;
}
.recommendations {
background: #eee;
margin: 0;
padding: 0;
display: none;
transition: all .2s ease;
}
.recommendations .card {
margin: -45px 0 0;
width: 300px;
}
.recommendations .card.visible {
animation: grow 1s ease;
}
@keyframes grow {
0% {transform: scale(0);}
70% {transform: scale(0);}
85% {transform: scale(1);}
95%{transform: scale(.95);}
100%{transform: scale(1);}
}
.recommendations h2 {
margin: 0;
padding: 15px 0 5px 20px;
text-transform: uppercase;
color: #666;
font-size: 18px;
}
.horizontal-scroll .slideRight {
position: absolute;
right: 0;
top: 50%;
margin-top: -40px;
height: 80px;
width: 50px;
outline: none;
border: none;
background: #666;
color: #ccc;
font-size: 28px;
cursor: pointer;
}
$(function() {
$('.categories .card button').on('click', function() {
var productType = $(this).parent().data('type'),
h3textbase = ' recommended for you',
expand = $(this).find('>:first-child'),
recs = $('.recommendations');
recs.css('margin-left', '0');
if($('.card .arrow').hasClass('down')) {
$('.card .arrow').removeClass('down').addClass('right');
}
if(expand.hasClass('right')) {
expand.removeClass('right').addClass('down');
} else {
expand.removeClass('down').addClass('right');
}
if (recs+':visible'){
recs.slideUp(100).html('').slideDown(400);
} else {
recs.html('').slideDown(400);
}
recs.append('<h2>'+productType+h3textbase+'</h2>');
var total = '';
$.each(products[productType], function(i,p){
recs.append('<a class="card" data-sku="'+p.sku+'">'+
'<img src="http://placehold.it/300x200/&text='+p.sku+'">'+
'<h3>'+p.title+'</h3>'+
'<h4>'+p.price+'</h4>'+
'<button>Add to cart</button>'+
'</a>');
total = i;
});
var fullWidth = (total+1)*300;
recs.width(fullWidth+'px');
$('.horizontal-scroll').append('<button class="slideRight">→</button>');
$('.slideRight').on('click', function(){
var firstFive = $('.recommendations > .card:lt(2)');
recs.append(firstFive);
});
$('.recommendations .card').addClass('visible');
});
});
var products = {
"jeans": [
{
"title": "Boot cut jeans",
"price": "34.99",
"sku": "0001"
},
{
"title": "Skinny jeans",
"price": "36.99",
"sku": "0002"
},
{
"title": "Sparkly jeans",
"price": "29.99",
"sku": "0003"
},
{
"title": "Hole-y jeans",
"price": "64.99",
"sku": "0004"
},
{
"title": "Faded jeans",
"price": "38.99",
"sku": "0005"
},
{
"title": "Vintage jeans",
"price": "31.99",
"sku": "0006"
},
{
"title": "Bell-bottom jeans",
"price": "38.99",
"sku": "0007"
},
{
"title": "Stretchy jeans",
"price": "37.99",
"sku": "0008"
},
{
"title": "Classic jeans",
"price": "38.99",
"sku": "0009"
},
{
"title": "Straight-cut jeans",
"price": "35.99",
"sku": "0010"
}
],
"shirts": [
{
"title": "Heavy metal t-shirt",
"price": "24.99",
"sku": "0011"
},
{
"title": "Turtle neck",
"price": "19.99",
"sku": "0012"
},
{
"title": "Plain white tee",
"price": "15.99",
"sku": "0013"
},
{
"title": "Nerdy logo t-shirt",
"price": "18.99",
"sku": "0014"
},
{
"title": "Long sleeve shirt",
"price": "21.99",
"sku": "0015"
},
{
"title": "Classic undershirt",
"price": "22.99",
"sku": "0016"
},
{
"title": "V-Neck shirt",
"price": "20.99",
"sku": "0017"
},
{
"title": "Hoodie shirt",
"price": "18.99",
"sku": "0018"
},
{
"title": "Tank top",
"price": "17.99",
"sku": "0019"
},
{
"title": "Sleeveless Tee",
"price": "21.99",
"sku": "0020"
}
],
"sweaters": [
{
"title": "Heavy running sweater",
"price": "31.99",
"sku": "0021"
},
{
"title": "Turtle neck sweater",
"price": "29.99",
"sku": "0022"
},
{
"title": "Plain black sweater",
"price": "25.99",
"sku": "0023"
},
{
"title": "Nerdy logo sweater",
"price": "41.99",
"sku": "0024"
},
{
"title": "Long sleeve sweater",
"price": "32.99",
"sku": "0025"
},
{
"title": "Classic sweater",
"price": "22.99",
"sku": "0026"
},
{
"title": "V-Neck sweater",
"price": "27.99",
"sku": "0027"
},
{
"title": "Hoodie sweater",
"price": "38.99",
"sku": "0028"
},
{
"title": "Wollen sweater",
"price": "50.99",
"sku": "0029"
},
{
"title": "Animal print sweater",
"price": "42.99",
"sku": "0030"
}
],
"hats": [
{
"title": "Bowler hat",
"price": "31.99",
"sku": "0031"
},
{
"title": "Cowboy hat",
"price": "29.99",
"sku": "0032"
},
{
"title": "Baseball cap",
"price": "25.99",
"sku": "0033"
},
{
"title": "Knit hat",
"price": "41.99",
"sku": "0034"
},
{
"title": "Watch cap",
"price": "32.99",
"sku": "0035"
},
{
"title": "Top hat",
"price": "22.99",
"sku": "0036"
},
{
"title": "Stocking cap",
"price": "27.99",
"sku": "0037"
},
{
"title": "Flex-fit hat",
"price": "38.99",
"sku": "0038"
},
{
"title": "Sun hat",
"price": "50.99",
"sku": "0039"
},
{
"title": "Leather hat",
"price": "42.99",
"sku": "0040"
}
],
"belts": [
{
"title": "Brown leather belt",
"price": "31.99",
"sku": "0041"
},
{
"title": "Black leather belt",
"price": "29.99",
"sku": "0042"
},
{
"title": "Crocheted belt",
"price": "25.99",
"sku": "0043"
},
{
"title": "Hemp belt",
"price": "41.99",
"sku": "0044"
},
{
"title": "White satin belt",
"price": "32.99",
"sku": "0045"
},
{
"title": "Animal print belt",
"price": "22.99",
"sku": "0046"
},
{
"title": "Plastic colored belt",
"price": "27.99",
"sku": "0047"
},
{
"title": "Safety belt",
"price": "38.99",
"sku": "0048"
},
{
"title": "Soft cotton belt",
"price": "50.99",
"sku": "0049"
},
{
"title": "Tanned leather belt",
"price": "42.99",
"sku": "0050"
}
],
"shorts": [
{
"title": "Running shorts",
"price": "31.99",
"sku": "0061"
},
{
"title": "Khaki shorts",
"price": "29.99",
"sku": "0062"
},
{
"title": "Short shorts",
"price": "25.99",
"sku": "0063"
},
{
"title": "Capri shorts",
"price": "41.99",
"sku": "0064"
},
{
"title": "Cargo shorts",
"price": "32.99",
"sku": "0065"
},
{
"title": "Board shorts",
"price": "22.99",
"sku": "0066"
},
{
"title": "Swim trunks",
"price": "27.99",
"sku": "0067"
},
{
"title": "Jean shorts",
"price": "38.99",
"sku": "0068"
},
{
"title": "Corduroy shorts",
"price": "50.99",
"sku": "0069"
},
{
"title": "Animal print shorts",
"price": "42.99",
"sku": "0070"
}
]
}
Also see: Tab Triggers