javascript - 如何在手机间隙使用 iscroll javascript?

标签 javascript html cordova cordova-2.0.0 iscroll

我已经尝试为我的应用程序实现 iscroll java 脚本作为 CSS position:fixed 的补救过程,它在使用 cordova 2.1.0< 的 android 2 和 3 版本中不起作用/强>

我从here复制了iscroll-lite的javascript

html代码

<div id="wrapper" class="wrapper">
<div id="wrapper-container" class="wrapper-container">
    <div id="header" class="header">
    <div id="header_title" class="header_title"> </div>
    <div id="abc" class="abc"><img src="img/abc.png""/>                     </div>
</div>
<div id="images" class="images"><img  name="slide" src="img/abc.png" width=100%; />
</div>
<div id="description"  class="description">
<div id="title" class="title">
    <h1><strong></strong></h1>
</div>
<div id="desc" class="desc">
</div>
</div>  

<div id="footer" style="background-image:url(img/bar.png);" class="footer">
<div id="footer_text" class="footer_text">footer_text</div>
<div id="image" class="image noSelect"><img src="img/info.png" onclick="info()"/></div>
</div>
</div>

desc标签内容要溢出

CSS

.wrapper
{
    position: absolute; width:auto; margin:0 auto; height:100%; overflow: hidden;
}
.wrapper_other
{
     width:auto; margin:0 auto; height:100%; overflow: hidden;
}
.wrapper_container
{
    width:100%;  margin:0 auto; font-family:Arial, Helvetica, sans-serif; 
}
.header
{
    float:left; height:100%;  min-height:100%; margin:0%; width:96%; padding:3% 2% 0;
}
.header_title
{
     float:left; padding:0%; margin:0%;  height:100%; min-height:100%; font-size:22px; color: #FFFFFF; text-align:center; font-weight: bold; width:80%; 
}

.images
{
    position:relative; width:100%;
}
.description
{
     float:left; width:100%; overflow:auto;  height:100%; 

}
.title
{
    width:85%; font-weight:bold; float:left; font-size:20px; margin-top:3%; margin-bottom:2%; margin-left:5%; color:#FFFFFF; 
}
.desc
{
      width:90%; font-size:15px; margin-left:5%; margin-right:5%; float:left; color: #FFFFFF; overflow:auto; text-align:justify; line-height:18px; padding:0px 0px 40px 0px; 
}
.desc p
{
      margin-top:0; 
}
.footer
{
     width:100%;  position:absolute; bottom:0; font-size:11px; color:#FFFFFF; text-align:center; height:30px;
}
.footer_text
{
    text-indent:1%; float:left; text-align:center;  width:75%;  margin-top:2%;
}
.info
{
    width:25%; float:right; padding-top:1%;
}

使用滚动

<script type="text/javascript" charset="utf-8" src="iscroll.js"></script>
<script type="text/javascript" charset="utf=8" src="cordova-2.1.0.js"></script> 


var myScroll;
document.addEventListener("deviceready", onDeviceReady, false);
function scroll() 
{
myScroll = new IScroll('.wrapper', { scrollX:false , scrollY:true});
}
----
----
function onDeviceReady() 
{   
    scroll();
    ----
    ----

滚动时,我得到以下信息

W/webview(3101): Miss a drag as we are waiting for WebCore's response for touch down.

问题:

它不是滚动的。如果经过巨大的努力它确实滚动了但是,它只滚动了一次。我返回主页并返回它根本不滚动。

请指导我!!

编辑:我已经尝试过各种组合..将所有 div 替换为 li 标签...css 无效。然后在每个 div 中使用 li 标签。没用...它没有滚动。:

<div id="wrapper">
<div id="scroller">
<ul>
  <div id="header " class="header ">
     <div id="header_title" class="header_title"> </div>
    <div id="xyz" class="xyz"><img src="img/xyz.png" onClick="xyz()"/></div>    </div>  </ul>

<ul>
      <div id="images" class="images"><img  name="slide" src="img/banner1.png" width=100%; />
   </div>
</ul>

<ul>
  <div id="param" class="param">
    <div id="abc" class="abc noSelect"> </div>
        <div id="def" class="def noSelect" > </div>
        <div id="ghi" class="ghi noSelect" > </div>
        <div id="ijk" class="ijk noSelect" > </div>
    </div>
</ul>

<ul>
  <div id="description"  class="description">
       <div id="title"  class="title">
    <h1><strong><li></li></strong></h1>
       </div>

    <div id="desc" class="desc">
    <p><li></li> </p>
    </div>
</div>

</ul>

最佳答案

您似乎没有遵循 iScroll 要求的结构。 iScroll 页面特别提到(注意粗体文本):

The optimal iScroll structure is:

<div id="wrapper">
  <ul>
      <li></li>
      ...
      ...
  </ul>
</div>

In this example the UL element will be scrolled. The iScroll must be applied to the wrapper of the scrolling area.

Important: only the first child of the wrapper element will be scrolled. If you need more elements inside the scroller you may use the following structure:

<div id="wrapper">
  <div id="scroller">
      <ul>
          <li></li>
          ...
          ...
      </ul>

      <ul>
          <li></li>
          ...
          ...
      </ul>
  </div>
</div>

In this example the scroller element will be scrolled (together with the two ULs).

你有:

<div id="wrapper" class="wrapper">
  <div id="wrapper-container" class="wrapper-container">
  ... head ...
  </div>

  ... (your main div here) ...
</div>

所以您的主 div 不会被 iScroller 滚动,您只是让标题 div 可滚动。看看 iScroll demo并先测试一下……它对您的设备是否有效?如果是,请尝试遵循其结构。

关于javascript - 如何在手机间隙使用 iscroll javascript?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16980231/

相关文章:

javascript - float 条形图可点击的条显示不正确的信息

html - CSS3 照片库过渡效果

javascript - 单击另一个div时如何添加li类

javascript - Cordova Android 构建失败 ("failed to find Build Tools revision 24.0.1")

javascript - 验证按钮后提交表单必须点击两次

javascript - 如何使用javascript根据输入值隐藏元素?

android - jQuery 移动按钮按下事件处理缓慢

javascript - JQuery Mobile + Phonegap : $. ajax 调用不工作

javascript - 按表达式过滤 ng-repeat

javascript - 从 Javascript 数组创建按钮数组