ng2-scroll-to
ng2-scroll-to copied to clipboard
target.offsetTop return 0
my target offsettop is always 0 . so i have made this modifications i think it can help
function getPosition(element, scrollingElement) {
var xPosition = 0;
var yPosition = 0;
while (element !== scrollingElement) {
xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
element = element.offsetParent;
}
return {x: xPosition, y: yPosition};
}
ScrollTo.prototype.onClick = function (event) {
event.preventDefault();
var scrollEnd;
if (this.scrollYTarget) {
if (isNaN(Number(this.scrollYTarget))) {
throw 'scrollYTarget must have numerical values';
}
scrollEnd = this.scrollYTarget;
}
var target;
var scrollingElement = this.getScrollableElement(target);
if (scrollEnd == null) {
target = this.getTarget();
if (!target) {
console.warn('target element do not exist');
return;
}
scrollEnd = getPosition(target,scrollingElement).y;
}
try {
if (scrollingElement === document.body) {
this.smoothScroll(document.documentElement, scrollEnd);
}
}
catch (e) {
console.warn(e);
}
this.smoothScroll(scrollingElement, scrollEnd);
};