【问题标题】:Scroll position of a jquery mobile 1.0 collapsible set when expanded展开时 jquery mobile 1.0 可折叠集的滚动位置
【发布时间】:2014-03-08 02:32:27
【问题描述】:

我的问题与this one 几乎相同,只是我使用的是 jQuery Mobile 1.0。整个项目已经编写完毕,我不想为了让这个滚动功能与我的可折叠套装一起使用而将其更新到 1.3.2。我可以从链接问题中提供的答案中使用任何可以适应 1.0 的内容吗?

谢谢

【问题讨论】:

    标签: javascript jquery jquery-mobile scroll jquery-mobile-collapsible


    【解决方案1】:

    为了使 滚动 正常工作,不需要升级。只是监听expand事件的方式不同。

    绑定

    $(".ui-collapsible").bind("expand", function () {
      /* scroll */
    });
    

    委托

    $(document).delegate(".ui-collapsible", "expand", function () {
      /* scroll */
    });
    

    滚动

    var position = $(this).offset().top;
    
    /* scroll with animation */
    $("html, body").animate({
        scrollTop: position
    });
    
    /* scroll without triggering scroll event */
    $.mobile.silentScroll(position);
    

    Demo

    【讨论】:

      【解决方案2】:

      非常感谢!现在完全有道理。对于那些阅读这篇文章的人,我还在顶部添加了一个偏移量,如下所示:

      var topoffset = 50;
      var position = $(this).offset().top - topoffset;
      
      /* scroll with animation */
      $("html, body").animate({
      scrollTop: position
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-01-14
        • 2018-08-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多