Last active
August 30, 2018 12:54
-
-
Save alim-nagoev/865f69987e89bf12459a5b60d41b683e to your computer and use it in GitHub Desktop.
This file contains hidden or 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
```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