android - 水平滚动在 phonegap 中不起作用

标签 android html jquery-mobile cordova horizontal-scrolling

请检查我在我的代码中犯了什么错误,我的水平滚动不起作用 提前致谢

在 jquery 中:-

      var step = 1;
var current = 0;
var maximum = $(".categories ul a").size();
var visible = 2;
var speed = 500;
var liSize = 120;
var height = 60;    
var ulSize = liSize * maximum;
var divSize = liSize * visible;

     $(document).unbind('pageinit').bind('pageinit', function () {    
          callMenuConnection(); 
           $('.categories').css("width", "auto").css("height", height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
           $(".categories ul a").css("list-style","none").css("display","inline");
           $(".categories ul").css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute").css("white-space","nowrap").css("margin","0px").css("padding","5px");      
      });

     $(document).unbind('click').bind('click', function () {

            scroll();
     });
       function callMenuConnection() {  

        $.support.cors = true;
           $.ajax({
                type: "GET",
                url: "http://192.162.1.205/EServices/retrieve.aspx?command=get_menu&outlet=RBC",
                contentType: "text/xml",
                dataType: "xml",
                data: "",
                cache:false,
                processData:false,
                crossDomain:true,
                success: processSuccess,
                error: processError
            }); 
      }
          var scripts ="";     
      function processSuccess(data) {
             $(data).find("category").each(function () {     
             var id = $(this).find('id').text();
             var title = $(this).find('title').text();



              scripts = scripts+'<span><a  data-role="button" data-transition="slide"  data-inline="true" >' +title+ '</a></span>';

            });

            $('#cat_list').append(scripts);
            $('#cat_list').trigger('create');

      }

         function processError(data)
           {
               alert("error");
           }

     function scroll(){           
       $(".cat_list_class").swipeleft(function(event){

    if(current + step < 0 || current + step > maximum - visible) {return; }
    else {
        current = current + step;
        $('.categories ul').animate({left: -(liSize * current)}, speed, null);
    }
    return false;
});

$(".cat_list_class").swiperight(function(){

    if(current - step < 0 || current - step > maximum - visible) {return; }
    else {
        current = current - step;
        $('.categories ul').animate({left: -(liSize * current)}, speed, null);
    }
    return false;
});         
}

在 html5 中:-

  <div data-role="page" data-theme="b" id="jqm-home">            
            <div class="categories" id="cat">                
                <ul id="cat_list" class="cat_list_class"></ul>               
      </div>
    </div>

最佳答案

终于得到了这些的答案

在 HTML5 中:-

 <div data-role="page" data-theme="b" id="jqm-home">    
      <div data-role="footer" data-position="fixed" data-theme="c">        
           <div  class="categories" id="cat">                
              <ul id="cat_list" class="cat_list_class"></ul>               
           </div>
      </div>    
</div>

在 jquery 中:-

 var step = 1;
 var current = 0;
   var maximum = 0;
  var visible = 2;
  var speed = 500;
 var liSize = 120;
 var height = 60;    
  var ulSize = liSize * maximum;
  var divSize = liSize * visible;

 $(document).unbind('pageinit').bind('pageinit', function () {    
      callMenuConnection(); 
       $('.categories').css("width", "auto").css("height", height+"px").css("visibility", "visible").css("overflow", "hidden").css("position", "relative");
       $(".categories ul a").css("list-style","none").css("display","inline");
       $(".categories ul").css("width", ulSize+"px").css("left", -(current * liSize)).css("position", "absolute").css("white-space","nowrap").css("margin","0px").css("padding","5px");      
  });

 $(document).unbind('click').bind('click', function () {
        scroll();
 });
   function callMenuConnection() {  
       $.support.cors = true;
       $.ajax({
            type: "GET",
            url: "one.html",
            contentType: "text/xml",
            dataType: "xml",
            data: "",
            cache:false,
            processData:false,
            crossDomain:true,
            success: processSuccess,
            error: processError
        }); 
  }
      var scripts ="";     
  function processSuccess(data) {
         $(data).find("category").each(function () {     
         var id = $(this).find('id').text();
         var title = $(this).find('title').text();
          scripts = scripts+'<a  class="ids_cat" data-role="button" data-transition="slide"  data-inline="true" >' +title+ '</a>';
        });
        $('#cat_list').append(scripts);
        $('#cat_list').trigger('create');
         maximum = $(".categories ul a").size();
  }

     function processError(data)
       {
           alert("error");
       }

 function scroll(){ 
 $(".categories").swipeleft(function(event){
  if(current + step < 0 || current + step > maximum - visible) {return; }
else {
    current = current + step;
    $('.categories ul').animate({left: -(liSize * current)}, speed, null);
}
return false;
});

    $(".categories").swiperight(function(event){
      if(current - step < 0 || current - step > maximum - visible) {return; }
        else {
        current = current - step;
         $('.categories ul').animate({left: -(liSize * current)}, speed, null);
     }
      return false;
  });         
  }

关于android - 水平滚动在 phonegap 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18100271/

相关文章:

android opengl es 在两个线程上运行的两个上下文之间共享纹理

android - 将 libav 链接到我的 Android NDK 项目时出错

java - 在测试用例中创建构造函数,使其仅被调用一次

php - 下拉(选择菜单)问题

jquery-mobile - 将按钮添加到标题右侧

java - 如何将文件写入 Android SD 卡并在 PC 上可见

html - 如何在 Elixir 中对字符串进行 html 解码?

jquery - 不考虑页面宽度的背景图像( Bootstrap )

android - 在 <div> 中显示 AR 浏览器。是否可以?

javascript - jQuery 移动 : Swipeleft/Swiperight is jumping itself