Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript document.ready not always working, iscroll !

Hello we are building a mobile web.app using iScroll for scrolling. The problem is that the iScroll scroller sometimes has problems working when the page loads at first.

This is the code, we added (document).ready to solve the problem, and it is doing it so mostly, but once in a while it doesn't seem to work.

Our guess is that the scroller isn't working when the height of the wrapper (scrollable area) loads to slow, that's why we added the document.ready with the results stated as above. https://stackoverflow.com/

<script type="text/javascript">

var myScroll;
$(document).ready(function loaded() {
    myScroll = new iScroll('wrapper');
});

$(document).ready.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

$(document).ready.addEventListener('DOMContentLoaded', loaded, false);

</script>`

We'd appreciate some help !

Thank you

like image 468
Hans Avatar asked Nov 29 '25 15:11

Hans


2 Answers

$(document).ready(); should not be called the way you have it after the first call.

$(document).ready.addEventListener

Also it looks like the third call to it is trying to overwrite it.

Try doing the following.

var myScroll;
$(document).ready(function {
    myScroll = new iScroll('wrapper');
    document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);
});
like image 71
Nalum Avatar answered Dec 01 '25 04:12

Nalum


ready is a method that takes a function as parameter and executes it when the document is ..well ready. so you should :

$(document).ready(function(){
    //do stuff here
});
like image 38
gion_13 Avatar answered Dec 01 '25 06:12

gion_13



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!