$(function(){
//colorbox
$(".gallery").colorbox({
rel: 'slideshow',
slideshow: false,
slideshowSpeed: 3000,
maxWidth: "85%",
maxHeight: "85%",
opacity: 0.8
});
//colorboxスワイプ切り替ãˆ
$('#colorbox').on('touchstart', onTouchStart); //指ãŒè§¦ã‚ŒãŸã‹æ¤œçŸ¥
$('#colorbox').on('touchmove', onTouchMove); //指ãŒå‹•ã„ãŸã‹æ¤œçŸ¥
$('#colorbox').on('touchend', onTouchEnd); //指ãŒé›¢ã‚ŒãŸã‹æ¤œçŸ¥
var direction, position;
//ã‚¹ãƒ¯ã‚¤ãƒ—é–‹å§‹æ™‚ã®æ¨ªæ–¹å‘ã®åº§æ¨™ã‚’æ ¼ç´
function onTouchStart(event) {
position = getPosition(event);
direction = ''; //一度リセットã™ã‚‹
}
//ã‚¹ãƒ¯ã‚¤ãƒ—ã®æ–¹å‘(leftï¼right)をå–å¾—
function onTouchMove(event) {
if (position - getPosition(event) > 70) { // 70px以上移動ã—ãªã‘れã°ã‚¹ãƒ¯ã‚¤ãƒ—ã¨åˆ¤æ–ã—ãªã„
direction = 'left'; //å·¦ã¨æ¤œçŸ¥
} else if (position - getPosition(event) < -70){ // 70px以上移動ã—ãªã‘れã°ã‚¹ãƒ¯ã‚¤ãƒ—ã¨åˆ¤æ–ã—ãªã„
direction = 'right'; //å³ã¨æ¤œçŸ¥
}
}
function onTouchEnd(event) {
if (direction == 'right'){
$.colorbox.next();
} else if (direction == 'left'){
$.colorbox.prev();
}
}
//横方å‘ã®åº§æ¨™ã‚’å–å¾—
function getPosition(event) {
return event.originalEvent.touches[0].pageX;
}
//リサイズ時ã®å‡¦ç†
$(window).resize(function() {
var timer = false;
if (timer !== false) { clearTimeout(timer); }
timer = setTimeout(function() {
$.colorbox.close();
}, 100);
});
});