zippy1978 / jquery.scrollz

Modern scrolling for jQuery
GNU General Public License v2.0
81 stars 17 forks source link

Allow Passing in of "top" Position to hidePullHeader #9

Closed AdamDash-2 closed 11 years ago

AdamDash-2 commented 11 years ago

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');
        }
      }
    }

  });
}
zippy1978 commented 11 years ago

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 ?

AdamDash-2 commented 11 years ago

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

zippy1978 commented 11 years ago

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

zippy1978 commented 11 years ago

Commited ! Thank you.