/* ================================================================ This copyright notice must be kept untouched in the script at all times. The original version of this script and the associated (x)html is available at https://www.cssplay.co.uk/menu/cssplay-swipe-me-mobils.html Copyright (c) Stu Nicholls. All rights reserved. This script and the associated (x)html may be modified in any way to fit your requirements. =================================================================== */ $(window).load(function () { currentSlide = 0; set = '.set1' $('.buttons div').prepend('') /* get Internet Explorer version */ var msVersion = navigator.userAgent.match(/MSIE ([0-9]{1,}[\.0-9]{0,})/), msie = !!msVersion, ie78 = msie && parseFloat(msVersion[1]) < 9; browser = msie && parseFloat(msVersion[1]) <= 9; /* if IE7 or IE8 change the background images for foreground images */ if (ie78) { $('.swipebg').css({display:'block'}); $('.slide').each(function () { bg = $(this).css("background-image"); bg = bg.replace(/"/g,"").replace(/url\(|\)$/ig, ""); if (bg != 'none') { $(this).css({'background-image':'none'}); $(this).append(''); } }); } /* resize the slides and re-calculate the left position when the window size/orientation changes */ $(window).resize(function() { $('.slides').removeClass('animate'); winWidth = $(window).width(); winHeight = $(window).height(); $('.swipeme').css({height:winHeight+'px'}); pixelOffset = -currentSlide*winWidth; updatePosition(set) if (ie78) {updateIE78()} }).resize(); $('.rightArrow').click(function() { $(set).addClass('animate'); currentSlide++ pixelOffset = currentSlide * -winWidth; updatePosition(set) updateButton() updateCaption() if (ie78) {updateIE78()} updateArrows() }); $('.leftArrow').click(function() { $(set).addClass('animate'); currentSlide-- pixelOffset = currentSlide * -winWidth; updatePosition(set) updateButton() updateCaption() if (ie78) {updateIE78()} updateArrows() }); /* the swipe routine */ function swipeMe(set) { var sliderMouseDown = false; $('.close').click(function() { $('.slides').removeClass('animate'); $('.slide').off(); $('.swipeme').fadeOut(100); $('html').css({overflow:'auto'}); $('body').css({overflow:'auto'}); $(set).fadeOut(100); $('.page').fadeIn(100); }); sliding = startClientX = startPixelOffset = pixelOffset = currentSlide = 0, slideCount = $(set+' .slide').length; $('.leftArrow').hide() $('.rightArrow').show() $(set).fadeIn(250); updatePosition(set) updateIE78() $('.buttons div span').remove() $(set+' .slide').each(function () { $('.buttons div').append('') }); updateButton() updateCaption() $('.slide').on("mousedown touchstart", function(event){ if (event.originalEvent.touches) event = event.originalEvent.touches[0]; sliding = 1; startClientX = event.clientX; sliderMouseDown = true; return false; }); $('.slide').on("mousemove touchmove", function(event){ if (sliderMouseDown) { event.preventDefault(); if (event.originalEvent.touches) event = event.originalEvent.touches[0]; var deltaSlide = event.clientX - startClientX; if (sliding == 1 && deltaSlide != 0) { sliding = 2; startPixelOffset = pixelOffset; } if (sliding == 2) { var touchPixelRatio = 1; if ((currentSlide == 0 && event.clientX > startClientX) || (currentSlide == slideCount - 1 && event.clientX < startClientX)) touchPixelRatio = 3; pixelOffset = startPixelOffset + deltaSlide / touchPixelRatio; $(set).removeClass('animate'); updatePosition(set) } } else {startClientX = event.clientX;} }); $('.slide').on("mouseup touchend", function(event){ if (sliding == 2) { sliding = 0; if (Math.abs(startPixelOffset-pixelOffset)>50) { currentSlide = pixelOffset < startPixelOffset ? currentSlide + 1 : currentSlide - 1; currentSlide = Math.min(Math.max(currentSlide, 0), slideCount - 1); } pixelOffset = currentSlide * -$(window).width(); $(set).addClass('animate'); updatePosition(set) updateButton() updateCaption() updateArrows() } sliderMouseDown = false; return false; }); } function updateArrows () { if ($('.leftArrow').is(':visible') || $('.rightArrow').is(':visible')) { $('.arrow').hide() if (currentSlide>0) { $('.leftArrow').show() } if (currentSlide'+newCaption+''); } } function updatePosition(set) { if (!browser) { $(set).css('-webkit-transform', 'translate3d(' + pixelOffset + 'px,0,0)'); $(set).css('-ms-transform', 'translateX(' + pixelOffset + 'px)'); $(set).css('-o-transform', 'translateX(' + pixelOffset + 'px)'); $(set).css('transform', 'translate3d(' + pixelOffset + 'px,0,0)'); } else { if ($(set).attr('class').indexOf('animate') != -1) { $(set).animate({'left': pixelOffset + 'px'}, 400); } else {$(set).css({'left': pixelOffset + 'px'});} } } /* resize the foreground images when the window size changes */ function updateIE78 () { winWidth = $(window).width(); winHeight = $(window).height(); $(".swipebg").each(function(){ paneRatio = winHeight/winWidth; imgHeight = $(this).height(); imgWidth = $(this).width(); imgRatio = imgHeight/imgWidth; bgsize = $(this).parent().attr("data-size"); if (bgsize == 'cover') { if (paneRatio>=imgRatio) { $(this).css({'top':'0px', height:winHeight+'px', width:'auto'}); leftPos=((winWidth-$(this).width())/2) $(this).css({'left':leftPos+'px'}); } else { $(this).css({'left':'0px', width:winWidth+'px', height:'auto'}); topPos=((winHeight-$(this).height())/2) $(this).css({'top':topPos+'px'}); } } if (bgsize == 'contain') { if (paneRatio<=imgRatio) { $(this).css({'top':'0px', height:winHeight+'px', width:'auto'}); leftPos=((winWidth-$(this).width())/2) $(this).css({'left':leftPos+'px'}); } else { $(this).css({'left':'0px', width:winWidth+'px', height:'auto'}); topPos=((winHeight-$(this).height())/2) $(this).css({'top':topPos+'px'}); } } if (bgsize == 'none') { leftPos=((winWidth-$(this).width())/2) $(this).css({'left':leftPos+'px'}); topPos=((winHeight-$(this).height())/2) $(this).css({'top':topPos+'px'}); } }); } $('.swipe').click(function() { $('.slides').removeClass('animate'); set = $(this).attr('data-set'); $('html').css({overflow:'hidden'}); $('body').css({overflow:'hidden'}); $('.page').hide(); $('.swipeme').fadeIn(250); swipeMe(set) }); });