(function(){ $.fn.touchtouch = function(){ var overlay = $('
'), slider = $('
'), prevarrow = $(''), nextarrow = $(''), pagespan = $('
')); }); slider.append(placeholders).on('click',function(e){ hideoverlay(); }); $('body').on('touchstart', '.galleryslider img', function(e){ var touch = e.originalevent, startx = touch.changedtouches[0].pagex; slider.on('touchmove',function(e){ e.preventdefault(); touch = e.originalevent.touches[0] || e.originalevent.changedtouches[0]; if(touch.pagex - startx > 10){ slider.off('touchmove'); showprevious(); } else if (touch.pagex - startx < -10){ slider.off('touchmove'); shownext(); } }); return false; }).on('touchend',function(){ slider.off('touchmove'); }); items.on('click', function(e){ e.preventdefault(); index = items.index(this); showoverlay(index); showimage(index); calcpages(items,index); preload(index+1); preload(index-1); offsetslider1(index); $(document).data("overlayvisible",true); e.cancelbubble = true; }); function calcpages(items,index){ pagespan.text((index+1)+"/"+items.length); } if ( !("ontouchstart" in window) ){ overlay.append(prevarrow).append(nextarrow); prevarrow.click(function(e){ e.preventdefault(); showprevious(); }); nextarrow.click(function(e){ e.preventdefault(); shownext(); }); } $(window).bind('keydown', function(e){ if (e.keycode == 37){ showprevious(); } else if (e.keycode==39){ shownext(); } }); function showoverlay(index){ if (overlayvisible){ return false; } overlay.show(); settimeout(function(){ overlay.addclass('visible'); }, 100); offsetslider1(index); overlayvisible = true; } function hideoverlay(){ if(!overlayvisible){ return false; } overlay.hide().removeclass('visible'); overlayvisible = false; $(document).data("overlayvisible",overlayvisible); } function offsetslider(index){ slider.stop(true).animate({left:(-index*100)+'%'},500); } function offsetslider1(index){ // slider.stop(true).animate({left:(-index*100)+'%'},500); slider.css('left',(-index*100)+'%'); } function preload(index){ settimeout(function(){ showimage(index); }, 1000); } function showimage(index){ if(index < 0 || index >= items.length){ return false; } loadimage(items.eq(index).attr('href'), function(){ placeholders.eq(index).html(this); }); } function loadimage(src, callback){ var img = $('').on('load', function(){ callback.call(img); }); img.attr('src',src); } function shownext(){ if(index+1 < items.length){ index++; offsetslider(index); preload(index+1); calcpages(items,index); } // return false; } function showprevious(){ if(index>0){ index--; offsetslider(index); preload(index-1); calcpages(items,index); } } }; })(jquery);