Skip to content
This repository has been archived by the owner on Mar 27, 2019. It is now read-only.

[pull down to refresh] <div class="iScrollPullUp">'s offsetHeight was not initialized causing the div to be displayed initially #20

Closed
thomasyip opened this issue Mar 7, 2011 · 2 comments

Comments

@thomasyip
Copy link
Contributor

The example works perfectly by itself. So, it is, technically, not a iScroll bug.

But, when the document get large, the offsetHeight is initialized at "0". (might be related to delay processing by long CSS file.)

Added a "0" timeout worked around the problem.

Index: iscroll.js
===================================================================
--- iscroll.js  (revision 1210)
+++ iscroll.js  (working copy)
@@ -83,10 +83,12 @@
                div.innerHTML = '<span class="iScrollPullDownIcon"></span><span class="iScrollPullDownLabel">' + that.options.pullDownLabel[0] + '</span>\n';
                that.scroller.insertBefore(div, that.scroller.children[0]);
                that.options.bounce = true;
-               that.offsetBottom = div.offsetHeight;
-               that.scroller.style.marginTop = -that.offsetBottom + 'px';
                that.pullDownEl = div;
                that.pullDownLabel = div.getElementsByTagName('span')[1];
+               setTimeout(function() {
+                       that.offsetBottom = div.offsetHeight;
+                       that.scroller.style.marginTop = -that.offsetBottom + 'px';
+               }, 0);
        }

        if (that.pullUpToRefresh) {
@@ -95,10 +97,12 @@
                div.innerHTML = '<span class="iScrollPullUpIcon"></span><span class="iScrollPullUpLabel">' + that.options.pullUpLabel[0] + '</span>\n';
                that.scroller.appendChild(div);
                that.options.bounce = true;
-               that.offsetTop = div.offsetHeight;
-               that.scroller.style.marginBottom = -that.offsetTop + 'px';
                that.pullUpEl = div;
                that.pullUpLabel = div.getElementsByTagName('span')[1];
+               setTimeout(function() {
+                       that.offsetTop = div.offsetHeight;
+                       that.scroller.style.marginBottom = -that.offsetTop + 'px';
+               }, 0);
        }

@thomasyip
Copy link
Contributor Author

Okay, it was not be caused by a large document but the fact that the ancestor div is set to display: none.

So, the reset() method should check offsetHeight again. I will provide a patch shortly.

@thomasyip
Copy link
Contributor Author

I sent a pull request:
https://github.com/cubiq/iscroll/issues/#issue/21

This one is closed as a dup.

vandrongelen pushed a commit to visualspace/jQTouch that referenced this issue Sep 9, 2011
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant