zippy1978/jquery.scrollz

Allow Passing in of "top" Position to hidePullHeader

Closed this issue · 4 comments

Possible enhancement.

Sometimes you want to preserve the scroll position that the user has when you pull to refresh. This should happen right after the pull header is hidden and isn't really possible outside of the control because of the animation so we pass in the position and do it in the animation callback. Also, when no animation, just scroll directly to the top position instead of just hiding the header...

/* Hides pull header */
hidePullHeader: function(animated, top) {

  // If animated parameter is not defined : then it is set to true
  animated = typeof  animated !== 'undefined' ? animated : true;
  top = typeof  top !== 'undefined' ? top : undefined;

  return this.each(function() {

    var $this = $(this);

    // If plugin initialized
    if (_isInitialized($this)) {

      var settings = $this.data('options');
      var container = _getMarkupCache($this, 'container');

      if (settings.pull) {
        if (animated) {
            container.animate({scrollTop: _getPullHeaderHeight($this)}, 'fast', function() {
            _changePullHeaderState($this, 'initial');

            if (typeof top !== 'undefined') {
                container.scrollTop(top)
            }
          });
        } else {
            if (typeof top !== 'undefined') {
                container.scrollTop(top)
            } else {
                container.scrollTop(_getPullHeaderHeight($this));
            }

            _changePullHeaderState($this, 'initial');
        }
      }
    }

  });
}

Hi !
I understand what your code does, but I can't find a real life example where I could use the 'top' parameter.
Do you have one ?

Yeah for sure. Have a look at the way Twitter does pull to refresh. When they have new messages, they put them above the current scroll position so when the pull to refresh closes, the user is not at the top of the stream, they are at the top of the last message they saw before the pull to refresh

Ok nice !
I will add it in the next release :)

Commited !
Thank you.