1

I have a problem with ionic framework's native scroll. The following works fine in the browser, but not when compiled to iOS. If I poll the $ionicScrollDelegate.getScrollPosition() at an interval, I don't get up-to-date values for positions. It's only if the deceleration ends or the user touches again that the value is updated. I spelunked through all the ionic scroll code, but it seems that the __scrollLeft value comes from an even deeper internal API since I'm trying to use native, not js scrolling.

In an attempt to hack around it, I tried using the DOM API to get the window-relative position of my content:

inversePosition = divContainer.getBoundingClientRect().left;

but this suffered from the same lack of updates. This makes me think it may not even be possible.

Is there a way to get the position more directly? I'm willing to dive into the ionic js bundle myself, but I don't know where to start in terms of even finding the core cordova scrolling API documentation.

Basically, my use-case is similar to that of a mapping app, I need realtime accurate scroll position data.

I opened an issue in the ionic lib, but I doubt anyone will get to it with 398 other open issues....

tagging phonegap because because phonegap wraps cordova as well, and solutions in phonegap may be applicable to this problem.

FlavorScape
  • 13,301
  • 12
  • 75
  • 117
  • pulling my hair out over this. Maybe we can get it deep in the cordova code in the xCode project? `UIScrollView`? – FlavorScape May 13 '16 at 05:40
  • In Nativescript i have the same type of problem, the position is not updated till i release the scroll event. I am curious if there is a native solution for this scroll problem which also can be used in Nativescript. – R Pelzer May 13 '16 at 09:06
  • So, I have a prototype solution I will post when I verify it. I basically simulate the physics of iOS to "predict" the value while it is decelerating. It would be nice if ionic/cordova could supply the targetContentOffset at the very least. if you had an accurate target, you could simulate the deceleration much more accurately. https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIScrollViewDelegate_Protocol/ – FlavorScape May 13 '16 at 16:54
  • You should prob remove the NativeScript tag. NativeScript doesn't wrap Cordova. It has nothing to do with Cordova, a browser or any DOM objects. – Brad Martin May 17 '16 at 19:08

2 Answers2

0

Check iScroll

I haven't used it in ionic projects, only in backbone-cordova projects, but I suppose that it will work the same.

It adds a lot of functionalities on the scroll at javascript level, Its a little difficult to implement, as it uses their own model of CSS and HTML, but it offers you a lot of things in exchange, for example, current position.

Víctor
  • 3,029
  • 3
  • 28
  • 43
  • my use-case is performance intense, and therefore requires native scroll as utilized by overflow-scroll. I cannot use javascript scrolling, it is too janky for my application. Believe me, i tried =) – FlavorScape May 13 '16 at 16:48
0

Please try below code to get scroll position info:

  • HTML
<div id="mySrollDiv">
...
</div>
  • JS:

var scrollTop = document.getElementById('mySrollDiv').scrollTop; var offsetHeight = document.getElementById('mySrollDiv').offsetHeight; var scrollHeight = document.getElementById('mySrollDiv').scrollHeight;