0

私はShadowboxとその迅速で簡単なセットアップが大好きです。ある写真から次の写真に移動するためのスワイプ機能を追加したいと思います。

現在jswipeを使用しており、スワイプジェスチャを正しく起動して、#sb-containerの外部でスライドショーを制御することはできますが、div内のどこでもスワイプジェスチャを機能させることはできません。

誰かがshadowbox.jsスライドショーを制御するためにスワイプナビゲーションをうまく統合しましたか?

これが私が構築しているサイトへのリンクです...

http://totophoto.mattwooddc.com/portfolio/commercial/

任意の提案をいただければ幸いです。ありがとうございました!

4

4 に答える 4

3

タッチスワイプを使用してこれを機能させることができました。

まず、ここからダウンロードできるtouchswipe jsファイルを含めます:https ://github.com/mattbryson/TouchSwipe-Jquery-Plugin

次に、次のコードを含めます。

$(document).ready(function(){

  $("#sb-body").swipe( {
      //Generic swipe handler for all directions
      swipeLeft:function(event, direction, distance, duration, fingerCount) {
         Shadowbox.next();
      },
      swipeRight:function(event, direction, distance, duration, fingerCount) {
         Shadowbox.previous();
      },
      //Default is 75px, set to 0 for demo so any distance triggers swipe
     threshold:0
  });
});  

私はこれをjquery-1.3.2で動作させることができました(古いものは知っていますが、クライアントが使用しているテンプレートのこのバージョンb / cにロックされています)

于 2013-07-29T22:00:15.343 に答える
2

私はなんとかそれを機能させることができました。

まず、 jQueryMobileからタッチイベントライブラリを「借用」しました。縮小されたコードは次のとおりです。

(function(e,t){e.each("touchstart touchmove touchend orientationchange tap taphold swipe swipeleft swiperight scrollstart scrollstop".split(" "),function(t,n){e.fn[n]=function(e){return e?this.bind(n,e):this.trigger(n)};e.attrFn[n]=true});var n="ontouchstart"in window,r="touchmove scroll",i=n?"touchstart":"mousedown",s=n?"touchend":"mouseup",o=n?"touchmove":"mousemove";e.event.special.scrollstart={enabled:true,setup:function(){function o(n,r){i=r;var s=n.type;n.type=i?"scrollstart":"scrollstop";e.event.handle.call(t,n);n.type=s}var t=this,n=e(t),i,s;n.bind(r,function(t){if(!e.event.special.scrollstart.enabled){return}if(!i){o(t,true)}clearTimeout(s);s=setTimeout(function(){o(t,false)},50)})}};e.event.special.tap={setup:function(){var t=this,n=e(t);n.bind(i,function(r){function p(e){if(e.type=="scroll"){i=true;return}var t=e.type=="touchmove"?e.originalEvent.touches[0]:e;if(Math.abs(l[0]-t.pageX)>10||Math.abs(l[1]-t.pageY)>10){i=true}}if(r.which&&r.which!==1||n.data("prevEvent")&&n.data("prevEvent")!==r.type){return false}n.data("prevEvent",r.type);setTimeout(function(){n.removeData("prevEvent")},800);var i=false,u=true,a=r.target,f=r.originalEvent,l=r.type=="touchstart"?[f.touches[0].pageX,f.touches[0].pageY]:[r.pageX,r.pageY],c,h;h=setTimeout(function(){if(u&&!i){c=r.type;r.type="taphold";e.event.handle.call(t,r);r.type=c}},750);e(window).one("scroll",p);n.bind(o,p).one(s,function(r){n.unbind(o,p);e(window).unbind("scroll",p);clearTimeout(h);u=false;if(!i&&a==r.target){c=r.type;r.type="tap";e.event.handle.call(t,r);r.type=c}})})}};e.event.special.swipe={setup:function(){var n=this,r=e(n);r.bind(i,function(n){function f(e){if(!u){return}var t=e.originalEvent.touches?e.originalEvent.touches[0]:e;a={time:(new Date).getTime(),coords:[t.pageX,t.pageY]};if(Math.abs(u.coords[0]-a.coords[0])>10){e.preventDefault()}}var i=n.originalEvent.touches?n.originalEvent.touches[0]:n,u={time:(new Date).getTime(),coords:[i.pageX,i.pageY],origin:e(n.target)},a;r.bind(o,f).one(s,function(e){r.unbind(o,f);if(u&&a){if(a.time-u.time<1e3&&Math.abs(u.coords[0]-a.coords[0])>30&&Math.abs(u.coords[1]-a.coords[1])<75){u.origin.trigger("swipe").trigger(u.coords[0]>a.coords[0]?"swipeleft":"swiperight")}}u=a=t})})}};(function(e){function s(){var e=r();if(e!==i){i=e;t.trigger("orientationchange")}}var t=e(window),n,r,i;e.event.special.orientationchange=n={setup:function(){if(e.support.orientation){return false}i=r();t.bind("resize",s)},teardown:function(){if(e.support.orientation){return false}t.unbind("resize",s)},add:function(e){var t=e.handler;e.handler=function(e){e.orientation=r();return t.apply(this,arguments)}}};n.orientation=r=function(){var e=document.documentElement;return e&&e.clientWidth/e.clientHeight<1.1?"portrait":"landscape"}})(jQuery);e.each({scrollstop:"scrollstart",taphold:"tap",swipeleft:"swipe",swiperight:"swipe"},function(t,n){e.event.special[t]={setup:function(){e(this).bind(n,e.noop)}}})})(jQuery)

セレクターエンジンといくつかの優れたヘルパー関数を利用するためにjQueryを含めました。

次に、シャドウボックスが通常は前のボタンと次のボタンを表示するギャラリーであるかどうかを確認します。そうである場合、シャドウボックスにはクラスが与えられ、.sb-touch2つのイベントハンドラーはそのセレクターでのタッチイベントの後にリッスンします。

var myApp = {
    SBAdjust: function() {
        if (Shadowbox.hasNext())
            $('#sb-body').addClass('sb-touch');

        $(document).on('swipeleft', '.sb-touch', function (e) {
            e.preventDefault();
            Shadowbox.next();
        });
        $(document).on('swiperight', '.sb-touch', function (e) {
            e.preventDefault();
            Shadowbox.previous();
        });
    }
}

もちろん、これらすべてをどこかで初期化する必要があるので、Shadowbox.init()プロパティを編集して、次のようにします。

Shadowbox.init({
    onOpen: myApp.SBAdjust,
    onClose: function() {
        $('.sb-touch').removeClass('sb-touch');
    }
});
于 2012-12-07T11:01:14.973 に答える
0

Jezen Thomasのソリューションは素晴らしいスタートでした!ただし、1回のスワイプで複数のスワイプイベントがトリガーされるため、うまくいきませんでした。スライドショーは、複数の画像を先に進めます。

Jezenのコードから始めて、最終的にjQuerySwipeを使用しましここで私の実装の動作を見ることができます。

お役に立てれば :)

于 2013-03-24T22:01:33.057 に答える
0

ありがとうJezenThomas:)その作品!「右から左へのスライド」効果がないことは知っていますが、とにかく便利です。ところで、写真を右クリック/タップして画像を変更する機能を少し追加しました。そのここ:

jQuery(function(){
    jQuery(document).on('click', '#sb-body', function(){
        Shadowbox.next();
    });
});

Shadowboxの標準コントロール(矢印)が小さすぎるため、携帯電話で使用できません。だから私はそれがどこでもうまく機能するシャドウボックスを手に入れたいと思っている人々に役立つことを願っています。

于 2013-03-27T17:01:02.870 に答える