I am using prettyPhoto for displaying images I get from Flickr. It is working great on the Desktop and on the iPad. For the iPad I wanted to add swiping gestures for switching images. So I was trying to add TouchSwipe.
Here is how I setup my prettyPhoto. Notice the callback.
function setupBox() {
$("a[rel^='prettyPhoto[gallery1]']").prettyPhoto({
slideshow: 5000,
social_tools: '',
animation_speed:'normal',
theme:'facebook',
changepicturecallback: function() {
setupSwipe();
}
});
}
Here is the callback function. '#fullResImg' is the selector for the Image.
function setupSwipe() {
$('#fullResImg').swipe({
swipe:function(event, direction, distance, duration, fingerCount) {
if( direction == 'left' ) {
$.prettyPhoto.changePage('next');
}else if ( direction == 'right' ) {
$.prettyPhoto.changePage('previous');
}
},
allowPageScroll: "none",
});
}
All the functions are called correctly, but the swipe is not detected. If I change the selector to '.pp_content' I can swipe in the bottom of the Box, but also not on the image itself.
I suspect, that it has something to do with the stacking of the box, but I stried several other selectors, which didn't work on the actual Image.
I'll include the markup of the pP Box here:
<div class="pp_pic_holder facebook" style="top: 90.5px; left: 80px; display: block; width: 816px;">
<div class="ppt" style="opacity: 1; display: block; width: 776px;">LN-RKI</div>
<div class="pp_top">
<div class="pp_left"></div>
<div class="pp_middle"></div>
<div class="pp_right"></div>
</div>
<div class="pp_content_container">
<div class="pp_left">
<div class="pp_right">
<div class="pp_content" style="height: 552px; width: 776px;">
<div class="pp_loaderIcon" style="display: none;"></div>
<div class="pp_fade" style="display: block;">
<a href="#" class="pp_expand" title="Expand the image" style="display: inline;">Expand</a>
<div class="pp_hoverContainer" style="height: 516px; width: 776px;">
<a class="pp_next" href="#">next</a>
<a class="pp_previous" href="#">previous</a>
</div>
<div id="pp_full_res"><img id="fullResImage" src="http://farm9.static.flickr.com/8489/8265747809_d0fca2a7c9_b.jpg" style="height: 516px; width: 776px;"></div>
<div class="pp_details" style="width: 776px;">
<div class="pp_nav" style=""><a href="#" class="pp_play">Play</a>
<a href="#" class="pp_arrow_previous">Previous</a>
<p class="currentTextHolder">1/50</p>
<a href="#" class="pp_arrow_next">Next</a>
</div>
<p class="pp_description" style="display: none;"></p>
<div class="pp_social"></div>
<a class="pp_close" href="#">Close</a>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="pp_bottom">
<div class="pp_left"></div>
<div class="pp_middle"></div>
<div class="pp_right"></div>
</div>
</div>
<div class="pp_overlay" style="opacity: 0.8; height: 954px; width: 959px; display: block;"></div>
So, has anyone here a clue on how to use TouchSwipe for swiping through images on prettyPhoto?
Thanks in advance!
I used the answer above to implement the same feature but with TouchWipe and found that instead of removing '.pp_hoverContainer' you can just add the swipe action to that element like so:
$(document).ready(function(){
function setupBox() {
$("a[rel^='prettyPhoto']").prettyPhoto({
social_tools: false,
theme:'dark_rounded',
changepicturecallback: function() {
setupSwipe();
}
});
}
function setupSwipe() {
$(".pp_hoverContainer").touchwipe({
wipeLeft: function() {
$.prettyPhoto.changePage('next');
},
wipeRight: function() {
$.prettyPhoto.changePage('previous');
},
min_move_x: 20,
min_move_y: 20,
preventDefaultEvents: true
});
}
setupBox();
});