1

我想在 phonegap 应用程序中滚动 html 表,我尝试使用 div 标签,但它在手机间隙中不起作用,但相同的代码在 safari 浏览器中工作

4

1 回答 1

2

将此 jquery 插件用于 iscroll,用法:将 data-iscroll="enable" 添加到您的页面。

<div style="height:as u need;>
            <div data-iscroll="scroller">

      // your table put here.
       </div>
     </div>

    (function($) {
     $(function() {

       var SafariWindowHeightFix = 34; // XXX:

       function fixed(elm) {
       if (elm.data("iscroll-plugin")) {
       return;
       }

       elm.css({
               overflow: 'hidden'
               });

       var barHeight = 0;
       var $header = elm.find('[data-role="header"]');
       if ($header.length) {
       $header.css({
                   "z-index": 1000,
                   padding: 0,
                   width: "100%"
                   });
       barHeight += $header.height();
       }

       var $footer = elm.find('[data-role="footer"]');
       if ($footer.length) {
       $footer.css({
                   "z-index": 1000,
                   padding: 0,
                   width: "100%"
                   }); 
       barHeight += $footer.height();
       }

       var $wrapper = elm.find('[data-role="content"]');
       if ($wrapper.length) {
       $wrapper.css({
                    "z-index": 1,"height":"600px"
                    });
       $wrapper.height($(window).height() - barHeight - SafariWindowHeightFix);
       $wrapper.bind('touchmove', function (e) { e.preventDefault(); });
       }
       var scroller = elm.find('[data-iscroll="scroller"]').get(1);
       var scroller1 = elm.find('[data-iscroll="scroller"]').get(0);

       if (scroller) {
       var iscroll = new iScroll(scroller, {desktopCompatibility:true});
       elm.data("iscroll-plugin", iscroll);
       }
       if (scroller1) {
       var iscroll1 = new iScroll(scroller1, {desktopCompatibility:true});
       elm.data("iscroll-plugin", iscroll1);
       } 
       }
       $('[data-role="page"][data-iscroll="enable"]').live("pageshow", function() {
                                                           fixed($(this));
                                                           });
       $('[data-role="dialog"][data-iscroll="enable"]').live("pageshow", function() {
                                                             fixed($(this));
                                                             }); 
       if ($.mobile.activePage.data("iscroll") == "enable") {
       fixed($.mobile.activePage);
       }
       });
     })(jQuery);
于 2012-07-26T09:00:08.273 回答