Created
November 23, 2017 17:51
-
-
Save chrishutchinson/3622f6ff6792a0af52f7bdaabb359c22 to your computer and use it in GitHub Desktop.
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
// Polymer template code | |
<!-- A permanently visible (although empty) anchor, so we have somewhere to scroll to --> | |
<div id="results-anchor"></div> | |
// Polymer JavaScript code | |
const scrollToElement = (element, offset = 0) => { | |
const distanceFromTop = element.getBoundingClientRect().top; | |
window.scrollBy({ | |
top: distanceFromTop + offset, | |
left: 0, | |
behavior: 'smooth', | |
}); | |
}; | |
// ... | |
showData: function(data) { | |
// ... | |
scrollToElement(this.$$('#results-anchor'), -40); | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment