Skip to content

Instantly share code, notes, and snippets.

@alim-nagoev
Last active August 30, 2018 12:54
Show Gist options
  • Save alim-nagoev/865f69987e89bf12459a5b60d41b683e to your computer and use it in GitHub Desktop.
Save alim-nagoev/865f69987e89bf12459a5b60d41b683e to your computer and use it in GitHub Desktop.
```js
function scrollIt(element) {window.scrollTo({'behavior': 'smooth','left': 0,'top': element.offsetTop});}
var btns = document.querySelectorAll('.js-btn');
var sections = document.querySelectorAll('.js-section');
btns[0].addEventListener('click', function () {scrollIt(sections[0]);});
btns[1].addEventListener('click', function () {scrollIt(sections[1]);});
```
```html
<div class="btns">
<button class="btn js-btn">Section 1</button>
<button class="btn js-btn">Section 2</button>
</div>
<div class="section js-section">scroll-behavior: smooth - Section 1</div>
<div class="section js-section">scroll-behavior: smooth - Section 2</div>
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment