d-oliveros / ngSmoothScroll

AngularJS directives for animating smooth scrolling to elements.
276 stars 110 forks source link

Fix to calculate correct scroll position if container is provided #86

Open stonys opened 7 years ago

stonys commented 7 years ago

If custom container if provided, the value of location is calculated incorrectly. Loop goes up to root element and adds up all offsetTop values. It should stop at the container provided and do not include parent element offsetTop values.

stonys commented 7 years ago

I didn't create a minified version, if you accept my PR, you could point the tool used for bundling.

danallen88 commented 4 years ago

Any reason we can't go ahead with merging this in? As it stands, the library doesn't work with custom containers without this fix. If your element.offsetParent is anything but the scroll container, you end up needing this along with setting the scroll container to have either absolute or relative positioning to make the scroll container the offsetParent, and then stopping since that's the container. Otherwise this just keeps going up the hierarchy until offsetParent becomes null, which isn't desirable since the container should be the top-level element to consider in this situation.