d-oliveros / ngSmoothScroll

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

smoothScroll doesn't work on SVG Elements #27

Closed WolfSoko closed 1 year ago

WolfSoko commented 9 years ago

Trying to use this awesome directive with SVG elements does not work. I seems the end position could not be calculated for SVG Elements.

I made a workaround by using the offset option and calculating the SVG-Element position. Would be aweseome if you integrate SVG support.

Position for svg element can be calculated like this:

//is SVG Element? 
if( element instanceof SVGElement) {
 return calcSVGPosition(element)
}
else calcNormalEndPosition(...);

function calcSVGPosition(element){
  var elementsRelativYPosition = element.getScreenCTM().f;
  var currentPos = $window.pageYOffset;
  var elementsAbsolutYPosition = currentPos + elementsRelativYPosition; 
  return elementsAbsolutYPosition;
}