AnythingSlider。如何在最后一张幻灯片上向右滑动以转到URL?

时间:2014-02-28 18:14:49

标签: jquery mobile anythingslider

如何在最后一张幻灯片上制作“swiperight”以转到网址? (就像在幻灯片6上单击“下一步”时那样)

http://nonoisenow.com/slideshow/

JS代码: http://nonoisenow.com/jscode/swiperight.js

有什么建议吗? 谢谢!

2 个答案:

答案 0 :(得分:1)

如果我正确阅读文档,您可以将“swipeleft”和“swiperight”添加到激活clickForwardArrow的事件列表中,并在jquery.anythingslider.js文件中单击“BackBackwardArrow”

这是交互性的原始文件部分:

// Interactivity
    clickForwardArrow   : "click",         // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
    clickBackArrow      : "click",         // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
    clickControls       : "click focusin", // Events used to activate navigation control functionality
    clickSlideshow      : "click",         // Event used to activate slideshow play/stop button
    allowRapidChange    : false,           // If true, allow rapid changing of the active pane, instead of ignoring activity during animation

添加事件后应该如何看待(我认为):

// Interactivity
    clickForwardArrow   : "click swiperight",         // Event used to activate forward arrow functionality (e.g. add jQuery mobile's "swiperight")
    clickBackArrow      : "click swipeleft",         // Event used to activate back arrow functionality (e.g. add jQuery mobile's "swipeleft")
    clickControls       : "click focusin", // Events used to activate navigation control functionality
    clickSlideshow      : "click",         // Event used to activate slideshow play/stop button
    allowRapidChange    : false,           // If true, allow rapid changing of the active pane, instead of ignoring activity during animation

答案 1 :(得分:0)

修改滑动代码以检查是否在最后一页上进行了滑动,如果是,则转到所需的网址(demo

if (newx < x) {
    if (slider.currentPage < slider.pages) {
        slider.goForward(); 
    } else if (slider.currentPage === slider.pages) {
        // swipe while on the last page will go to google
        // doesn't work in this demo because of iframes
        window.location.href = 'http://google.com';
    }
}

以下是完整代码:

/******************************************
  Swipe Demo - without using jQuery Mobile
 ******************************************/

$('#slider').anythingSlider({

    // Callback when the plugin finished initializing
    onInitialized: function(e, slider) {

        var time = 1000, // allow movement if < 1000 ms (1 sec)
            range = 50,  // swipe movement of 50 pixels triggers the slider
            x = 0, t = 0, touch = "ontouchend" in document,
            st = (touch) ? 'touchstart' : 'mousedown',
            mv = (touch) ? 'touchmove' : 'mousemove',
            en = (touch) ? 'touchend' : 'mouseup';

        $('<div class="swipe-overlay"></div>')
            .appendTo(slider.$window)
            .bind(st, function(e){
                // prevent image drag (Firefox)
                e.preventDefault();
                t = (new Date()).getTime();
                x = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX; 
            })
            .bind(en, function(e){
                t = 0; x = 0;
            })
            .bind(mv, function(e){
                e.preventDefault();
                var newx = e.originalEvent.touches ? e.originalEvent.touches[0].pageX : e.pageX,
                r = (x === 0) ? 0 : Math.abs(newx - x),
                // allow if movement < 1 sec
                ct = (new Date()).getTime();
                if (t !== 0 && ct - t < time && r > range) {
                    if (newx < x) {
                        if (slider.currentPage < slider.pages) {
                            slider.goForward(); 
                        } else if (slider.currentPage === slider.pages) {
                            // swipe while on the last page will go to google
                            // doesn't work in this demo because of iframes
                            window.location.href = 'http://google.com';
                        }
                    }
                    if (newx > x) { slider.goBack(); }
                    t = 0; x = 0;
                }
            });

    }

});