jquery - 将多个 jquery 循环与 ipad 的 touchwipe(滑动)事件结合使用

标签 jquery ipad mobile touch jquery-cycle

我已将循环插件设置为在一个页面上多次工作,一切正常。我正在尝试使用 touchwipe 插件添加一个滑动事件,该插件在单周期轮播上运行良好,但我无法让它在多个轮播上工作。

这是我的 Javsacript,显示了 Cycle 代码,以及底部的 Touchwipe 添加:

function galleries () {     

    var counter = 1

    $('.gallery .pics').each(function() {
        $(this).parent().attr('id','slideshow_'+counter);
        $(this).before('<ul class="next-prev-nav"><li><a href="#" class="prev-'+counter+'">Previous</a></li><li><a href="#" class="next-'+counter+'">Next</a></li></ul><div style="clear:both;"></a>');
        $(this).after('<ul class="gallery-nav-'+counter+'">');
        $(this).cycle({
            fx: 'scrollHorz',
            speed:  '400', 
            timeout: '4000', 
            pager:  '.gallery-nav-'+counter,
            next: '.next-'+counter,
            prev: '.prev-'+counter,
            pause:   1,
            pauseOnPagerHover: true, 
            startingSlide: 0, // zero-based 

            pagerAnchorBuilder: function(id, slide) { 
                var s = $(slide);
                var imgsource = s.find('img.CycIMG').attr('src');

                // Set this as the source for our image
                return '<li><a href="#"><img src="' + imgsource + '" width="62" alt=""></a></li>';  
            }
        }).cycle('pause');
        $(this).touchwipe({
            wipeLeft: function() {
                $('.pics').cycle('next');       
            },
            wipeRight: function() {
                $(this).cycle('prev');
            }
        });
        counter++;
    });
}

从 $(this).touchwipe 开始的代码行是我无法工作的。我在这里展示两个不同的例子。 “wipeLeft”函数可以工作,但由于它针对的是通用类(“pics”),因此它会立即滑动所有轮播。 “wipeRight”函数是我希望它工作的方式,使用“this”,仅针对循环中的当前循环轮播。我尝试为一开始创建的每个轮播指定单独的 ID,但这似乎不起作用。

非常感谢任何帮助!

最佳答案

尝试在代码中添加上下文选择器:

$('.gallery .pics').each(function() {
    var parent = this.parentNode;

    /*...*/

    $(this).touchWipe({
        wipeLeft: function(){
            $('.pics', parent).cycle('next');
        }
    });
});

它的作用是将“上下文”添加到您的选择器中。它类似于:$(parent).find('.pics')

我实际上正在处理与您完全相同的情况,并且我已经测试过它是否有效:)

关于jquery - 将多个 jquery 循环与 ipad 的 touchwipe(滑动)事件结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11462919/

相关文章:

jquery - Caroufredsel 在 Firefox 中不可见

iphone - 设备方向将改变而不是已经改变

java - 图像处理应用程序的内存使用情况

iOS动画不保持最后位置

ios - 如何为 iPad (iOS 8.1) 创建表单弹出窗口

android - 移动设备的自动化框架

javascript - 使用 javascript 从数据库显示

javascript - 如何在 css 中将侧边栏与 youtube 播放器对齐

javascript - 为什么我无法在 Javascript 中访问 window.variable?

javascript - jQuery 手机-Gap :- Does the Auto-Dividers in list view is working or not?