MCPcopy
hub / github.com/angular-ui/ui-grid / scrollTo

Function scrollTo

lib/test/angular/1.7.0/angular.js:5335–5361  ·  view source on GitHub ↗
(elem)

Source from the content-addressed store, hash-verified

5333 }
5334
5335 function scrollTo(elem) {
5336 if (elem) {
5337 elem.scrollIntoView();
5338
5339 var offset = getYOffset();
5340
5341 if (offset) {
5342 // `offset` is the number of pixels we should scroll UP in order to align `elem` properly.
5343 // This is true ONLY if the call to `elem.scrollIntoView()` initially aligns `elem` at the
5344 // top of the viewport.
5345 //
5346 // IF the number of pixels from the top of `elem` to the end of the page's content is less
5347 // than the height of the viewport, then `elem.scrollIntoView()` will align the `elem` some
5348 // way down the page.
5349 //
5350 // This is often the case for elements near the bottom of the page.
5351 //
5352 // In such cases we do not need to scroll the whole `offset` up, just the difference between
5353 // the top of the element and the offset, which is enough to align the top of `elem` at the
5354 // desired position.
5355 var elemTop = elem.getBoundingClientRect().top;
5356 $window.scrollBy(0, elemTop - offset);
5357 }
5358 } else {
5359 $window.scrollTo(0, 0);
5360 }
5361 }
5362
5363 function scroll(hash) {
5364 // Allow numeric hashes

Callers 1

scrollFunction · 0.70

Calls 1

getYOffsetFunction · 0.70

Tested by

no test coverage detected