Automattic / antiscroll

OS X Lion style cross-browser native scrolling on the web that gets out of the way.
1.07k stars 162 forks source link

Dynamically appearing elements #59

Closed urban-1 closed 6 years ago

urban-1 commented 11 years ago

Hi,

This is a small fix for elements that appear on run-time (ie. onclick of a button) and their content changes. Since they have display hidden initially I had to call .antiscroll() every time I show an element, in order to reset the scroll bars (I don't know if there is a better way of doing this...).

Now this causes constant size expansion each time the element appears (due to the css width += scrollbarSize() in the initialization function). My solution was to remove this extra width/height in the destroy():

  Antiscroll.prototype.destroy = function () {

    this.inner.css({
        'width':  '-=' + (this.y ? scrollbarSize() : 0)
      , 'height': '-=' + (this.x ? scrollbarSize() : 0)
    });

    if (this.horizontal) {
      this.horizontal.destroy();
      this.horizontal = null
    }
    if (this.vertical) {
      this.vertical.destroy();
      this.vertical = null
    }
    return this;
  };

Please let me know if I am doing something wrong, but seems reasonable to me to add this code in destroy, just to leave the element in its original state. This will also solve problems when antiscroll() is called multiple times.

Andreas

setthase commented 11 years ago

:+1: