简体   繁体   English

如何在SwipeView中使用iScroll4?

[英]How to use iScroll4 with SwipeView?

I'm using iScroll4 to create a horizontal scroll effect on an image within a mobile website. 我正在使用iScroll4在移动网站上的图像上创建水平滚动效果。 iScroll works fantastic, but the problem is the image contained in the iScroll wrapper disables native vertical scrolling. iScroll非常棒,但问题是iScroll包装器中包含的图像会禁用本机垂直滚动。 In other words, a user's finger swipe to navigate the page is disabled anywhere within the iScroll wrapped image. 换句话说,在iScroll包装图像内的任何位置禁用用户的手指滑动以导航页面。

SwipeView may be able to solve this problem, but the documentation (atleast for me) is not that clear. SwipeView可能能够解决这个问题,但文档(至少对我来说)并不是那么清楚。 Does anyone know how to effectively use SwipeView on an iScroll wrapped image? 有谁知道如何在iScroll包装图像上有效使用SwipeView?

sorry to pretty much reproduce the answer that's already been made - but I need to paste some code into a different space. 很抱歉几乎重现了已经做出的答案 - 但我需要将一些代码粘贴到不同的空间。

Alastair's example didn't quite work for me. 阿拉斯泰尔的例子并不适合我。 The version of iScroll I downloaded didn't seem to support matching a class, it wanted an object. 我下载的iScroll版本似乎不支持匹配类,它想要一个对象。 So since my project has jQuery already I used that to pass the active element in. 因为我的项目已经有了jQuery,所以我用它来传递活动元素。

scroller = new iScroll($('.swipeview-active')[0], {
  hScroll: false,
  lockDirection: true,
  hideScrollbar: true,
  fadeScrollbar: true
});

I added this to the end of the carousel.onFlip() function from the example at demo/inline/test.html in the download for http://cubiq.org/swipeview 我在http://cubiq.org/swipeview下载的demo / inline / test.html示例中将此添加到carousel.onFlip()函数的末尾

Haven't done extended testing - this is just something I'm looking at a bit while comparing cominbation of libraries to use but it's working as you'd expect in Chrome using the code above. 还没有进行扩展测试 - 这只是我在比较库的使用时所看到的一些内容,但它正如您在Chrome中使用上述代码所期望的那样工作。

EDIT Just tested in mobile safari on iphone too link here https://dl.dropbox.com/u/81328343/scroll/test.html 编辑刚刚在iphone手机游戏测试中也链接到这里https://dl.dropbox.com/u/81328343/scroll/test.html

Only thing (not sure if it's good or bad, depends on use case) is that when returning to a slide it jumps back to the top. 唯一的事情(不确定它的好坏,取决于用例)是当返回到幻灯片时它会跳回到顶部。

I've found the documentation to be terribly lacking as well but something like this works for me: 我发现文档非常缺乏,但这样的东西对我有用:

function swipeView(wrapper){
        wrapper = new SwipeView('#wrapper', {
        numberOfPages: pages.length
    });

    wrapper.onFlip(function(){
        scroller = new iScroll('.swipeview-active', {
            hScroll: false,
            lockDirection: true
        });
    });
}

This initialises iScroll on your current SwipeView page upon swiping to it. 这会在刷到当前的SwipeView页面时初始化iScroll。 Horizontal iScroll-scrolling is disabled which leaves that event available to SwipeView and the direction is locked so while a vertical (iScroll) swipe is in progress, a change in the user's swipe-direction won't swipe to the next SwipeView page. 水平iScroll-scrolling被禁用,使该事件可用于SwipeView并且方向被锁定,因此当垂直(iScroll)滑动正在进行时,用户滑动方向的更改将不会滑动到下一个SwipeView页面。 Without those options, one can do a bizarre horizontal swipe. 如果没有这些选项,可以进行奇怪的水平滑动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM