This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
commonLib.factory('scrollHelper', ['$timeout', function ($timeout) { | |
//scroll to element recursively until found | |
function scrollToElement(scrollToId, maxRetry) { | |
var counter = 0; | |
function tryScroll() { | |
counter ++; | |
var el = document.getElementById(scrollToId); | |
if (el) { | |
el.scrollIntoView(true); | |
} else if (counter < maxRetry) { | |
//try scroll again | |
$timeout(tryScroll, counter * 10); | |
} | |
}; | |
$timeout(tryScroll, 0); | |
}; | |
return { | |
scrollToElement: scrollToElement | |
}; | |
}]); | |