Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

ScrollView - scroll finished?

Hi everyone,

If I add a 'scroll' event listener to a ScrollView, is it possible to tell when the scroll has effectively finished?

Thanks,

Toby

— asked September 30th 2010 by Toby Mathews
  • ipad
  • scrollview
0 Comments

1 Answer

  • In case it helps anyone else, here's what I currently have - this is adapted/simplified from my actual implementation, apologies if I've broken it in the process (it seems to be working for me though):

    var lastCenter = '';
    var scrollTimeout;
    
    scrollMap.addEventListener('scroll', function(e) {
    
        if (lastCenter != null) {
            var offset = Titanium.UI.currentWindow.scrollMap.contentOffset;
            if (e.dragging || 
                (lastCenter.x == offset.x && lastCenter.y == offset.y)) {
    
                if (scrollTimeout != null) {                       
                    clearTimeout(scrollTimeout);
                }
    
                scrollTimeout = setTimeout(scrollFinish, 100);
            }
        }
    
        lastCenter = scrollMap.contentOffset;
    });
    
    Titanium.UI.currentWindow.add(scrollMap);
    Titanium.UI.currentWindow.scrollMap = scrollMap;
    
    lastCenter = Titanium.UI.currentWindow.scrollMap.contentOffset;
    
    function scrollFinish() {
        // Do some stuff after scrolling has finished.
    }
    
    — answered September 30th 2010 by Toby Mathews
    permalink
    1 Comment
    • I tried it with the event 'scrollEnd' (yes, it works for ScrollViews), but this one works better (recognizes a long dragging end, too). The clue here is the timeout, otherwise you are overwhelmed by events. Tried it with SDK 1.7.2.

      — commented September 3rd 2011 by Kai Müller
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.