简体   繁体   English

iscroll scrollToElement不更新currPage变量

[英]iscroll scrollToElement not updating currPage variable

UPDATE: I was able to get my scroller working as desired but I feel like I have hacked around the actual issue and would love it if anyone has a more solid answer, I've updated and noted in the snippets below the new jQuery I'm using. 更新:我能够让我的卷轴按照需要工作,但我觉得我已经破解了实际问题,如果有人有更坚实的答案我会喜欢它,我已经更新并注意到新jQuery下面的片段我'使用。

I'm using iScroll-4 ( http://cubiq.org/iscroll-4 ) for an iPad/Android web app, everything's working perfectly with the swipes and scrolling but I have a table of contents at the beginning of the app that allows users to jump to specific areas of the scroller -- 我正在使用iScroll-4( http://cubiq.org/iscroll-4 )用于iPad / Android网络应用程序,所有内容都与滑动和滚动完美配合,但我在应用程序开头有一个目录允许用户跳转到滚动条的特定区域 -

I'm using the iScroll function scrollToElement(element, duration) in order to jump to the different areas. 我正在使用iScroll函数scrollToElement(element, duration)来跳转到不同的区域。 Also using scrollToPage(page, duration) to allow the user to manually navigate forward and backward one page at a time. 还使用scrollToPage(page, duration)允许用户一次手动向前和向后导航一页。

While watching the console logs the currPageX variable updates when I navigate with the scrollToPage function and when I swipe, but when using the scrollToElement the currPageX variable does not update. 当我使用scrollToPage函数导航时,当我在使用scrollToElement时,观察控制台记录currPageX变量更新时, currPageX变量不会更新。

Therefore if I jump to an element and then navigate forward with scrollToPage('next', 0) it will go backwards and navigate me to the next page after the table of contents. 因此,如果我跳转到一个元素,然后使用scrollToPage('next', 0)向前导航,它将向后移动并导航到目录之后的下一页。

I have tried using the scroll.refresh() function after scrollToElement , before, putting the function inside a timeout, etc. and I can't figure out why the currPageX is not updating. 我已经尝试在scrollToElement之后使用scroll.refresh()函数,之前将函数放入超时等等,我无法弄清楚为什么currPageX没有更新。

Here's a snippet of the jQuery code that I'm using the two different functions: 这是我使用两个不同函数的jQuery代码片段:

  // TO NAVIGATE FORWARD AND BACKWARDS
  $('span.control').on('click', function() {
    var slideDir = $(this).attr('data-dir');
    if (slideDir == 'prev') {
      var tehPg = tehScroll.currPageX-1;
    } else if (slideDir == 'next') {
      var tehPg = tehScroll.currPageX+1;
    }
    tehScroll.scrollToPage(tehPg, 0);
    return false;
  });

  // TO JUMP FROM CONTENTS
  $('li[data-page="toc"] span').on('click', function() {
    var toPage = $(this).attr('data-page');
    tehScroll.scrollToElement('li[data-page="'+toPage+'"]', 800);
    // ADDED THE FOLLOWING LINE TO MANUALLY SET currPageX after scrolling!
    tehScroll.currPageX = $('#slides li[data-page="'+toPage+'"]').index();
    return false;
  });

Did you consider using jquery-mobile-iscrollview widget plug-in? 您是否考虑过使用jquery-mobile-iscrollview widget插件? - there is a function scrollToPage(pageX, pageY, time), works well for me... - 有一个函数scrollToPage(pageX,pageY,time),对我有用...

best 最好

M 中号

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

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