abouolia / sticky-sidebar

😎 Pure JavaScript tool for making smart and high performance sticky sidebar.
https://abouolia.github.io/sticky-sidebar/
MIT License
2.23k stars 489 forks source link

sidebar-inner not horizontal responsive #70

Open Lennie132 opened 6 years ago

Lennie132 commented 6 years ago

I noticed that if my div is on its 'static' location, it does resize like it shoud. But when it is in sticky position, it stays the same size on resize.

In your code I noticed that it can't resize because in calcDimensions(), it always uses it's own inner width. dims.sidebarWidth = this.sidebarInner.offsetWidth; // OLD

An easy fix is to not use it's sidebarInner width, but it's sidebar width.

dims.sidebarWidth = this.sidebar.offsetWidth; // NEW/FIX

  /**
       * Calculates dimensions of sidebar, container and screen viewpoint
       * @public
       */
      calcDimensions(){
        if( this._breakpoint ) return;
        var dims = this.dimensions;

        // Container of sticky sidebar dimensions.
        dims.containerTop    = StickySidebar.offsetRelative(this.container).top;
        dims.containerHeight = this.container.clientHeight;
        dims.containerBottom = dims.containerTop + dims.containerHeight;

        // Sidebar dimensions.
        dims.sidebarHeight = this.sidebarInner.offsetHeight;
        dims.sidebarWidth  = this.sidebar.offsetWidth; // NEW
        dims.sidebarWidth  = this.sidebarInner.offsetWidth; // OLD

        // Screen viewport dimensions.
        dims.viewportHeight = window.innerHeight;

        // Maximum sidebar translate Y.
        dims.maxTranslateY = dims.containerHeight - dims.sidebarHeight;

        this._calcDimensionsWithScroll();
      }
erichomanchuk commented 6 years ago

Definitely need this fix. Tried it out works great.

pcbliss commented 3 years ago

Perfect. I needed this fix as well