Skip to content

Instantly share code, notes, and snippets.

@paulstraw
Created March 7, 2016 18:21
Show Gist options
  • Select an option

  • Save paulstraw/80b5c2c8473f2d9067f9 to your computer and use it in GitHub Desktop.

Select an option

Save paulstraw/80b5c2c8473f2d9067f9 to your computer and use it in GitHub Desktop.
Using Drift with multiple images and images loaded via ajax
<img class="thumb" src="http://assets.imgix.net/dog.png?w=100" data-zoom="http://assets.imgix.net/dog.png?w=1200">
<img class="thumb" src="http://assets.imgix.net/cat.png?w=100" data-zoom="http://assets.imgix.net/cat.png?w=1200">
<img class="thumb" src="http://assets.imgix.net/frog.png?w=100" data-zoom="http://assets.imgix.net/frog.png?w=1200">
<img class="thumb" src="http://assets.imgix.net/llama.png?w=100" data-zoom="http://assets.imgix.net/llama.png?w=1200">
<p>Aenean lacinia bibendum nulla sed consectetur. Vestibulum id ligula porta felis euismod semper. Donec id elit non mi porta gravida at eget metus. Donec ullamcorper nulla non metus auctor fringilla.</p>
<div class="more-thumbs">
</div>
// Using vanilla JS to demo multiple image handling
var thumbs = document.querySelectorAll('.thumb');
var para = document.querySelector('p');
for (var i = 0, len = thumbs.length; i < len; i++) {
var thumb = thumbs[i];
new Drift(thumb, {
paneContainer: para
});
}
// Using jQuery to demo AJAX loading
var moreThumbsContainer = $('.more-thumbs');
moreThumbsContainer.load('more-thumbs.html', function() {
moreThumbsContainer.find('.more').each(function(i, el) {
new Drift(el, {
paneContainer: para
});
});
});
<img class="more" src="http://assets.imgix.net/trees.png?w=100" data-zoom="http://assets.imgix.net/trees.png?w=1200">
<img class="more" src="http://assets.imgix.net/mountains.png?w=100" data-zoom="http://assets.imgix.net/mountains.png?w=1200">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment