Skip to content

Instantly share code, notes, and snippets.

@chrishutchinson
Created November 23, 2017 17:51
Show Gist options
  • Save chrishutchinson/3622f6ff6792a0af52f7bdaabb359c22 to your computer and use it in GitHub Desktop.
Save chrishutchinson/3622f6ff6792a0af52f7bdaabb359c22 to your computer and use it in GitHub Desktop.
// 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