Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save celticwebdesign/ec7f2a496d0eaef95a8aa8ec23b553f5 to your computer and use it in GitHub Desktop.
Save celticwebdesign/ec7f2a496d0eaef95a8aa8ec23b553f5 to your computer and use it in GitHub Desktop.
HCV
HTML - add data-attribute(clicked-node) to each photo with counter.
jQuery
// PhotoSwipe
$(".grid-item img").click(function(e) {
e = e || window.event;
e.preventDefault ? e.preventDefault() : e.returnValue = false;
var index = $(this).data('clicked-node');
if(index >= 0) {
// open PhotoSwipe if valid index found
openPhotoSwipe( index );
}
return false;
});
// PhotoSwipe
function openPhotoSwipe(startAt) {
if( $('#inline1').length > 0 ) {
var pswpElement = document.querySelectorAll('.pswp')[0];
var test2_obj = $( "#inline1 div" ).data('src');
var arr = [];
$.each( test2_obj, function(key, value) {
arr.push({
src: value.src,
w: value.wid,
h: value.hei
});
});
var options = {
index: startAt // start at first slide
};
// Initializes and opens PhotoSwipe
var gallery = new PhotoSwipe( pswpElement, PhotoSwipeUI_Default, arr, options);
gallery.init();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment