Created
June 15, 2016 08:09
-
-
Save celticwebdesign/ec7f2a496d0eaef95a8aa8ec23b553f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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