【问题标题】:framework7 with swiper.js swipe scroll to top not working带有swiper.js的framework7滑动滚动到顶部不起作用
【发布时间】:2016-10-18 06:26:51
【问题描述】:

我用 swiper 有这个功能。我想知道如何使用此功能滚动回下一张幻灯片的页面顶部。到目前为止,当我使用我不想要的 onAutoplay 回调时,它只会滚动到下一张幻灯片的顶部。我的幻灯片有不同的滚动文本和图像,这就是为什么我想在向左或向右滑动时返回到下一张或上一张幻灯片的顶部。如果可能的话,请给我一个例子如何改进我的 sn-p。谢谢。

$$(document).on('pageInit', function (e) {
    var mySwiper = myApp.swiper('.swiper-container',{
      pagination: '.swiper-pagination',
      paginationHide: false,
      onSlideChangeEnd: function(swiper) {
        $(".page-content").animate({
            scrollTop: 0
        }, 'slow');
      }
    });                

  })

【问题讨论】:

    标签: swiper html-framework-7 phonegap-desktop-app


    【解决方案1】:

    将您的代码更改为:

    var mySwiper = new Swiper('.swiper-container');
    mySwiper.on('slideChangeEnd',function(){ alert('sample alert');});
    

    有关 swiper API 的更多信息: Swiper API documentation

    【讨论】:

    • 感谢您的回答。我正在尝试这个功能
    • $$(document).on('pageInit', function (e) { var mySwiper = myApp.swiper('.swiper-container',{ pagination: '.swiper-pagination', paginationHide : false, onSlideChangeEnd: function(swiper) { $(".position").animate({ scrollTop: 0 }, 'slow'); } }); })
    • 但它仍然没有滚动到下一张幻灯片的顶部
    • 我想在我告诉你的修改之前警报没有工作。现在,既然您坚持只使用一个函数来初始化 swiper,请将 onSlideChangeEnd 更改为:onSlideChangeEnd: function('.swiper-container'){ the rest of your code here },。我认为问题在于,由于您的 swiper 尚未初始化,因此程序不了解您尝试将什么“swiper”参数传递给函数。
    • self.swiper.on('slideChange', function () { $(".page-content").animate({ scrollTop: 0 }); }); 试试这个它在我的代码上的工作
    猜你喜欢
    • 2013-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-20
    相关资源
    最近更新 更多