Update images demo.

pull/111/head
Glen Cheney 8 years ago
parent 832503415d
commit eef5c66b31

@ -3,7 +3,7 @@
<div class="col-3@sm col-3@xs figure-wrap js-demo">
<a href="{{ site.baseurl }}/{{ post.slug }}">
<figure>
<div class="keep-ratio four-three">
<div class="aspect aspect--4x3">
<picture>
<source srcset="{{ site.baseurl }}/img/demos/{{ post.slug }}.webp" type="image/webp">
<img src="{{ site.baseurl }}/img/demos/{{ post.slug }}.jpg" alt="{{ post.label }}">

@ -50,7 +50,7 @@ extraCSS: [ "/css/gallery.css" ]
<div class="shape-up js-shuffle">
{% for shape in site.shapes %}
<div class="col-3@sm shape shape--{{ shape.shape }} shape--{{ shape.color }}" data-shape="{{ shape.shape }}" data-color="{{ shape.color }}">
<div class="keep-ratio">
<div class="aspect">
<div class="shape__inner">
<div class="shape__space">
</div>

@ -1,62 +1,50 @@
---
layout: default
title: Using images with imagesloaded.js
description: A Shuffle.js demo using Desandro's imagesLoaded plugin. This comes in very handy when using shuffle with images affect the layout of shuffle items
title: Using images with Shuffle
description: A Shuffle.js demo using aspect ratios to set the size of images.
image: /demos/images.jpg
extraJS: [ "imagesloaded.pkgd.js", "demos/images.js"]
extraJS: ["demos/images.js"]
prism: true
---
<div class="container">
<h2>Images!</h2>
<h2>Using images with Shuffle</h2>
<p>You can encounter problems when shuffle item dimensions depend on images. <a href="{{ site.baseurl }}{% post_url 2013-06-29-image-problems %}">Like this demo</a>. There are three good solutions to this.</p>
<ol>
<li>Set an explicit height on <code>.shuffle-item</code>s like the <a href="{{ site.baseurl }}{% post_url 2013-05-01-basic %}">basic demo</a>.</li>
<li>Similar to number 1, make the height of the image container a percentage of the width. This can be seen in the nav images above with the <code>div.keep-ratio</code>.</li>
<li>Get notified when images load (this page). In this case, I'm using <a href="http://desandro.github.io/imagesloaded/">Desandro's images loaded plugin</a>. Please note that imagesloaded does not support IE7.</li>
<li>Similar to number 1, make the height of the image container a percentage of the width. If you know the aspect ratio of the images you're using, this is the technique you should use. This demo uses this technique.</li>
<li>Get notified when images load and call <code>myShuffleInstance.layout()</code>. I recommend using <a href="http://desandro.github.io/imagesloaded/">Desandro's images loaded plugin</a> to know when your images have finished loading.</li>
</ol>
</div>
<style>
.shuffle-wrap {
position: relative;
}
.shuffle--images {
.my-grid-with-images {
position: relative;
visibility: hidden;
overflow: hidden;
}
.shuffle--images.images-loaded {
visibility: visible;
}
.shuffle--images .img-item {
.my-grid-with-images .img-item {
margin-top: 10px;
margin-left: 0;
}
.shuffle--images .img-item img {
.my-grid-with-images .img-item img {
width: 100%;
}
.loader {
position: absolute;
top: 50%;
left: 50%;
margin-top: -16px;
margin-left: -16px;
}
</style>
<div class="container shuffle-wrap">
<img id="loader" class="loader" alt="Loading..." src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMTYiIGhlaWdodD0iMTYiIHZpZXdCb3g9IjAgMCAzMDAgMzAwIgogICAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmVyc2lvbj0iMS4xIj4KICA8cGF0aCBkPSJNIDE1MCwwCiAgICAgICAgICAgYSAxNTAsMTUwIDAgMCwxIDEwNi4wNjYsMjU2LjA2NgogICAgICAgICAgIGwgLTM1LjM1NSwtMzUuMzU1CiAgICAgICAgICAgYSAtMTAwLC0xMDAgMCAwLDAgLTcwLjcxMSwtMTcwLjcxMSB6IgogICAgICAgIGZpbGw9IiMzZDdmZTYiPgogICAgPGFuaW1hdGVUcmFuc2Zvcm0gYXR0cmlidXRlTmFtZT0idHJhbnNmb3JtIiBhdHRyaWJ1dGVUeXBlPSJYTUwiCiAgICAgICAgICAgdHlwZT0icm90YXRlIiBmcm9tPSIwIDE1MCAxNTAiIHRvPSIzNjAgMTUwIDE1MCIKICAgICAgICAgICBiZWdpbj0iMHMiIGR1cj0iMXMiIGZpbGw9ImZyZWV6ZSIgcmVwZWF0Q291bnQ9ImluZGVmaW5pdGUiIC8+CiAgPC9wYXRoPgo8L3N2Zz4K" />
<div class="shuffle--images row">
<div class="my-grid-with-images row">
{% for item in site.items %}
<figure class="js-item img-item col-3@sm col-3@xs">
<img src="{{ site.baseurl }}/img/{{ item.img }}" alt="{{item.title}}"/>
<div class="aspect aspect--16x9">
<div class="aspect__inner">
<img src="{{ site.baseurl }}/img/{{ item.img }}" alt="{{item.title}}"/>
</div>
</div>
<figcaption>{{ item.groups }}</figcaption>
</figure>
{% endfor %}
@ -65,12 +53,70 @@ prism: true
</div>
<section>
<div class="container">
<h2>Shuffle.js</h2>
<p>{{ site.longDescription }}</p>
<div class="container has-code-block">
<div class="row">
<div class="col-12@sm">
<h2>Setup</h2>
</div>
<div class="col-12@sm">
<h3>Maintaining aspect ratios</h3>
<p>With two elements, you can create a box which will scale with the page. Here's an example:</p>
<div style="width:30%;">
<div class="aspect aspect--2x1" style="background-color: #3498DB; color: white;">
<div class="aspect__inner">
<div class="table-center-wrap text-center full-width full-height">
<div class="table-center">A 2:1 box</div>
</div>
</div>
</div>
</div>
<p>With this knowledge, you can force an image to fit inside this box and, when the image loads, it will not change the size of the box.</p>
<div class="code-block">
<pre rel="CSS"><code class="language-css">.aspect {
position: relative;
width: 100%;
height: 0;
padding-bottom: 100%;
overflow: hidden;
}
.aspect__inner {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
/* Add more aspect ratios here */
.aspect--16x9 {
padding-bottom: 56.25%;
}</code></pre>
</div>
</div>
<div class="col-12@sm">
<h3>Markup for each item</h3>
<p>The most important thing here is that the images are wrapped in two other elements which define its size. This means that the size of the <code>&lt;figure&gt;</code> does not depend on the image.</p>
<div class="code-block">
<pre data-line="2-6" rel="HTML"><code class="language-markup">&lt;figure class="js-item img-item col-3@sm col-3@xs"&gt;
&lt;div class="aspect aspect--16x9"&gt;
&lt;div class="aspect__inner"&gt;
&lt;img src="/img/tennis-ball.png" alt="3D render of a tennis ball"&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;figcaption&gt;wallpaper3d&lt;/figcaption&gt;
&lt;/figure&gt;</code></pre>
</div>
</div>
<div class="col-12@sm">
<h3>JavaScript used for this demo</h3>
<p>Link to <a href="{{ site.baseurl }}/js/demos/images.js">demo source</a></p>
<div class="code-block">
<pre rel="JavaScript" data-src="{{ site.baseurl }}/js/demos/images.js"></pre>
</div>
</div>
</div>
</section>
</div>
{% include credit-jake.html %}

@ -2,34 +2,35 @@
layout: default
title: Image based items
description: A demo of how NOT to use images with shuffle
extraJS: [ "demos/images-broken.js"]
extraJS: [ "demos/images.js"]
---
<div class="container">
<h2>This probably looks broken.</h2>
<p>Demo in which shuffle item dimensions are based on images without a fix. <a href="{{ site.baseurl }}{% post_url 2013-05-03-images %}">See here</a> for a solution.</p>
<p>In this demo, the height of each item in the grid depends on the image. If Shuffle is initialized before the images load, the heights it calculates will be incorrect. <a href="{{ site.baseurl }}{% post_url 2013-05-03-images %}">See here</a> for a solution.</p>
<p>Resize the window and it'll fix itself.</p>
</div>
<style>
.shuffle--images {
.my-grid-with-images {
position: relative;
overflow: hidden;
}
.shuffle--images .img-item {
.my-grid-with-images .img-item {
margin-top: 10px;
margin-left: 0;
}
.shuffle--images .img-item img {
.my-grid-with-images .img-item img {
width: 100%;
}
</style>
<div class="container">
<div class="shuffle--images row">
<div class="my-grid-with-images row">
{% for item in site.items %}
<figure class="js-item img-item col-3@sm col-3@xs">
<img src="{{ site.baseurl }}/img/{{ item.img }}" alt="{{item.title}}"/>

@ -37,8 +37,8 @@ pagejs: false
<div id="grid" class="shuffle--container row">
{% for item in site.items %}
<figure class="js-item img-item col-3@sm col-3@xs">
<div class="keep-ratio four-three">
<div class="keep-ratio-inner">
<div class="aspect aspect--4x3">
<div class="aspect__inner">
<img src="{{ site.baseurl }}/img/{{ item.img }}" alt="{{item.title}}"/>
</div>
</div>

@ -25,6 +25,11 @@
}
}
// .aspect
.#{$grid-ratio-name} {
@include keep-aspect();
}
// .aspect--16x9 etc.
@include grid-ratios();

@ -4,27 +4,6 @@
display: inline-block;
}
.aspect,
.keep-ratio {
position: relative;
width: 100%;
height: 0;
overflow: hidden;
padding-bottom: 100%;
&.four-three {
padding-bottom: 75%;
}
}
.aspect--4x3 {
padding-bottom: 75%;
}
.aspect--16x9 {
padding-bottom: 56.25%;
}
// Hide from both screenreaders and browsers.
.hidden {
display: none !important;
@ -58,6 +37,9 @@
float: right;
}
.full-width { width: 100%; }
.full-height { height: 100%; }
.hide-text {
font: 0/0 a;
color: transparent;

@ -105,7 +105,7 @@
// IE8 filter alpha wasn't working with the positioning stuff
.lt-ie9 .shape {
.keep-ratio {
.aspect {
position: static;
width: 100%;
height: 250px;

@ -65,7 +65,7 @@
border-width: 0 110px 191px 110px;
background-color: transparent; }
.lt-ie9 .shape .keep-ratio {
.lt-ie9 .shape .aspect {
position: static;
width: 100%;
height: 250px;

@ -1,4 +1,4 @@
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+scss */
/* http://prismjs.com/download.html?themes=prism&languages=markup+css+clike+javascript+scss&plugins=line-highlight+file-highlight */
/**
* prism.js default theme for JavaScript, CSS and HTML
* Based on dabblet (http://dabblet.com)
@ -136,3 +136,51 @@ pre[class*="language-"] {
.token.entity {
cursor: help;
}
pre[data-line] {
position: relative;
padding: 1em 0 1em 3em;
}
.line-highlight {
position: absolute;
left: 0;
right: 0;
padding: inherit 0;
margin-top: 1em; /* Same as .prisms padding-top */
background: hsla(24, 20%, 50%,.08);
background: -moz-linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -webkit-linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: -o-linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
background: linear-gradient(to right, hsla(24, 20%, 50%,.1) 70%, hsla(24, 20%, 50%,0));
pointer-events: none;
line-height: inherit;
white-space: pre;
}
.line-highlight:before,
.line-highlight[data-end]:after {
content: attr(data-start);
position: absolute;
top: .4em;
left: .6em;
min-width: 1em;
padding: 0 .5em;
background-color: hsla(24, 20%, 50%,.4);
color: hsl(24, 20%, 95%);
font: bold 65%/1.5 sans-serif;
text-align: center;
vertical-align: .3em;
border-radius: 999px;
text-shadow: none;
box-shadow: 0 1px white;
}
.line-highlight[data-end]:after {
content: attr(data-end);
top: auto;
bottom: .4em;
}

@ -538,6 +538,13 @@ h3:hover > a {
-ms-flex-pack: center;
justify-content: center; }
.aspect {
position: relative;
width: 100%;
height: 0;
overflow: hidden;
padding-bottom: 100%; }
.aspect--16x9 {
padding-bottom: 56.25%; }
@ -1171,23 +1178,6 @@ button {
.ib {
display: inline-block; }
.aspect,
.keep-ratio {
position: relative;
width: 100%;
height: 0;
overflow: hidden;
padding-bottom: 100%; }
.aspect.four-three,
.keep-ratio.four-three {
padding-bottom: 75%; }
.aspect--4x3 {
padding-bottom: 75%; }
.aspect--16x9 {
padding-bottom: 56.25%; }
.hidden {
display: none !important;
visibility: hidden; }
@ -1214,6 +1204,12 @@ button {
.pull-right {
float: right; }
.full-width {
width: 100%; }
.full-height {
height: 100%; }
.hide-text {
font: 0/0 a;
color: transparent;

@ -1,54 +1,6 @@
var Shuffle = window.shuffle;
// For this demo, shuffle won't be initialized until
// all the images have finished loading.
// Another approach would be to initialize shuffle on document
// ready and as imagesLoaded reports back progress, call shuffle.layout()
// imagesLoaded: https://github.com/desandro/imagesloaded
var ImageDemo = (function( $, imagesLoaded ) {
var $shuffle = $('.shuffle--images'),
$imgs = $shuffle.find('img'),
$loader = $('#loader'),
sizer = document.getElementById('js-sizer'),
imgLoad,
init = function() {
// Create a new imagesLoaded instance
imgLoad = new imagesLoaded( $imgs.get() );
// Listen for when all images are done
// will be executed even if some images fail
imgLoad.on( 'always', onAllImagesFinished );
},
onAllImagesFinished = function( instance ) {
if ( window.console && window.console.log ) {
console.log( instance );
}
// Hide loader
$loader.addClass('hidden');
// Adds visibility: visible;
$shuffle.addClass('images-loaded');
// Initialize shuffle
$shuffle.shuffle({
sizer: sizer,
itemSelector: '.js-item'
});
};
return {
init: init
};
}( jQuery, window.imagesLoaded ));
$(document).ready(function() {
ImageDemo.init();
window.myShuffle = new Shuffle(document.querySelector('.my-grid-with-images'), {
itemSelector: '.js-item',
sizer: '.shuffle__sizer',
});

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save