ng2-scroll-to icon indicating copy to clipboard operation
ng2-scroll-to copied to clipboard

target.offsetTop return 0

Open yaronmil opened this issue 7 years ago • 0 comments

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

yaronmil avatar Jun 05 '17 09:06 yaronmil