Is there jQuery Mobile's equivalent to the Android's ViewPager?

前端 未结 1 1830
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-11 06:05

I want to create a horizontal swiping effect using jQuery Mobile. After doing a little bit of research, I found out that ViewPager, which is generally found in the app details p

1条回答
  •  滥情空心
    2021-02-11 06:30

    I like SwipeJS, it's lightweight and I like the one-to-one slide factor it uses (when you slide your finger across the element, it moves at the same rate).

    There is also iScroll 4 that works pretty well (it seems to be more difficult to setup than SwipeJS).

    You can however utilize the built-in swipe events in jQuery Mobile. You can bind to the swipeleft or swiperight events for the data-role="page" element(s) and navigate the user to the correct page based on the current page:

    $(document).delegate('#page-two', 'swipeleft', function () {
        //next page
        $.mobile.changePage($('#page-three'));
    }).delegate('#page-two', 'swiperight', function () {
        //prev page
        $.mobile.changePage($('#page-one'), { reverse : true });
    });
    

    Here is a demo: http://jsfiddle.net/fFGvD/

    Notice the { reverse : true } object being passed as the option object to the changePage() function so the animation will play in reverse.

    0 讨论(0)
提交回复
热议问题