<link href="css/swipeshow/jquery.swipeshow.css" rel="stylesheet" /> <link href="css/swipeshow/style.css" rel="stylesheet" /> <link href="css/swipeshow/slideshow-theme.css" rel="stylesheet" /> <link rel="stylesheet" type="text/css" href="css/jquery.fancybox.css"> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script> <script src="js/swipeshow-master/jquery.swipeshow.min.js"></script> <script src="js/jquery.fancybox.js"></script> |
<script type="text/javascript"> jQuery(function ($) { 'use strict'; var chkTouch = ('ontouchstart' in window); // タッチデバイスかどうか? var mypopup = document.getElementsByClassName('mypopup'), // classから要素取得 mypopupCount = mypopup.length, // cache the length i; function startDrag(evt) { // ドラッグorクリックスタート var diffX = evt.pageX - this.offsetLeft, diffY = evt.pageY - this.offsetTop, that = this; var diff ; $(that).fancybox({'href':that.getAttribute("rel")}); // fancybox事前発行 document.addEventListener('touchend', stopDrag); document.addEventListener('touchmove', moveAlong); document.addEventListener('mouseup', stopDrag); document.addEventListener('mousemove', moveAlong); function stopDrag(evt) { // ボタンアップ $(that).trigger("click"); // 強制クリック発行(fancyboxのタップ起動不能対策) document.removeEventListener('mouseup', stopDrag); document.removeEventListener('touchend', stopDrag); document.removeEventListener('touchmove', moveAlong); document.removeEventListener('mousemove', moveAlong); } function moveAlong(evt) { //ドラッグ中 diff = Math.abs(evt.pageX - diffX); if ( diff > 1 ) { // 位置がずれてたらドラッグしている evt.preventDefault(); // スクロール抑制 $(that).off('click.fb-start'); // fancybox起動抑制 $(that).unbind('click'); // クリック発行取り消し } } function display(evt) { // fancybox起動 relタグの中身(画像URL)をhrefに渡す $(that).fancybox({'href':that.getAttribute("rel")}); } } for (i = 0; i < mypopupCount; i += 1) { // 複数ゲットしたclassをforで順番に処理 if ( chkTouch == false ) { mypopup[i].addEventListener('mousedown', startDrag); // PC } else { mypopup[i].addEventListener('touchstart', startDrag); // タッチデバイス } } }); </script> |
<div class="slideshow swipeshow"> <ul class="slides"> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/1-big.jpg"><img src="ugallery_cvt/1.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/2-big.jpg"><img src="ugallery_cvt/2.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/3-big.jpg"><img src="ugallery_cvt/3.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/4-big.jpg"><img src="ugallery_cvt/4.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/5-big.jpg"><img src="ugallery_cvt/5.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/6-big.jpg"><img src="ugallery_cvt/6.jpg" alt="" /></div> </li> <li class="slide"> <div class="mypopup" rel="ugallery_cvt/7-big.jpg"><img src="ugallery_cvt/7.jpg" alt="" /></div> </li> </ul> <!--<button class='previous'></button> <button class='next'></button>--> <div class='dots'></div> </div> <script> (function($) { $(".version").text($.swipeshow.version); $(".slideshow").swipeshow({ mouse: true, interval: 6000 }); })(jQuery); </script> |