简体   繁体   中英

iscroll does not working

I am using iScroll to one of my phonegap app. The way my template is setup like this. I have index.html. and I am loading pages dynamically via jQuery load() method. So what happens is when I launch the app then it loads login.html dynamically. and after that I use iscroll refresh method. So it works when I scroll for the first ime until the end of the page but then it it does not scroll when I want to scroll for the second time. And for this I get this error in my logcat

Miss a drag as we are waiting for WebCore's response for touch down

How can I make it work?

Here is my index.html

<header>
    Header
</header>
<div id="wrapper">
    <div id="scroll-content">

    </div>
</div>
<footer>
    <ul>
        <li><a href="#">Home</a></li>
        <li><a href="#">Profile</a></li>
        <li><a href="#">Photos</a></li>
    </ul>
</footer>
</body>
<script type="text/javascript">
var theScroll;
function scroll() {
    theScroll = new iScroll('wrapper', { vScrollbar: true });
}
document.addEventListener('DOMContentLoaded', scroll, false);
</script>

Here is my js file

jQuery(function () {
var myScroll = new iScroll('wrapper');
var Login = {
    onDeviceReady : function () {
        $('#scroll-content').load('./pages/login.html', function () {
            setTimeout(function () {
                myScroll.refresh();
            }, 0);
        });
        $(document).on('touchstart', '#btnlogin', Login.validate);
    },
    validate : function (e) {
        e.preventDefault();
        var input;
        $('#loginform input').each(function () {
            input = $(this).val();
            if(input == "") {
                $(".errormsg").html('Enter all mandatory fields');
                $(this).addClass('error');
            }
        });
    }
};

document.addEventListener("deviceready", Login.onDeviceReady, false);
});

here is my css

footer {
  background-color: #c27b00;
  position: absolute;
  z-index: 2;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 48px;
  padding: 0;
  border-top: 1px solid #444; }
  footer ul {
margin: 0;
padding: 0; }
footer ul li {
  display: inline-block;
  padding: 5% 10.5%;
  background-color: #fafafa; }
  footer ul li a {
    width: 100%;
    height: 100%; }
 body #wrapper {
position: absolute;
z-index: 1;
top: 45px;
bottom: 48px;
left: 0;
width: 100%;
background: #aaa;
overflow: auto; }
body #wrapper #scroll-content {
  position: absolute;
  z-index: 1;
  width: 100%;
  padding: 0; }

Check my answer here: https://stackoverflow.com/a/18726304/1959362

In your case try to call the refresh() method on 'pageshow' event like so:

$('#<id-of-your-jqm-page>').on('pageshow', function() {
    setTimeout(function () {
        myScrollFunction .refresh();
    }, 100);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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