bryanmcquade / scroll-to-css-selector

Explainer for supporting CSS selectors when navigating to a URL fragment
61 stars 1 forks source link

Bikeshed: polyfill #7

Open jonathantneal opened 6 years ago

jonathantneal commented 6 years ago
const selectors = new URLSearchParams(window.location.hash.slice(1)).get('target')
const element = selectors && document.querySelector(selectors)

if (element) {
  element.scrollIntoView()
}