Kebab file names

This commit is contained in:
Angelos Chalaris
2023-04-27 21:58:35 +03:00
parent 1d189c709a
commit 61200d90c4
440 changed files with 0 additions and 0 deletions

25
snippets/smooth-scroll.md Normal file
View File

@ -0,0 +1,25 @@
---
title: Smooth scroll element into view
tags: browser,css
cover: carrots
firstSeen: 2018-03-02T18:22:51+02:00
lastUpdated: 2020-10-22T20:24:30+03:00
---
Smoothly scrolls the element on which it's called into the visible area of the browser window.
- Use `Element.scrollIntoView()` to scroll the element.
- Use `{ behavior: 'smooth' }` to scroll smoothly.
```js
const smoothScroll = element =>
document.querySelector(element).scrollIntoView({
behavior: 'smooth'
});
```
```js
smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar
smoothScroll('.fooBar');
// scrolls smoothly to the first element with a class of fooBar
```