From 77cc7bb3cd0d098d0b8c6335ddada1039ed513e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Fri, 2 Mar 2018 17:22:51 +0100 Subject: [PATCH 1/4] add smoothScroll --- snippets/smoothScroll.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 snippets/smoothScroll.md diff --git a/snippets/smoothScroll.md b/snippets/smoothScroll.md new file mode 100644 index 000000000..0e3d3aa94 --- /dev/null +++ b/snippets/smoothScroll.md @@ -0,0 +1,17 @@ +### smoothScroll + +Smoothly scrolls the element on which it's called into the visible area of the browser window. + +Use `.scrollIntoView` method to scroll the element. Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly. + +```js +const smoothScroll = (element) => + document.querySelector(element).scrollIntoView({ + behavior: 'smooth' + }); +``` + +```js +smoothScroll('#fooBar'); // scrolls smoothly to the element with the id of fooBar +smoothScroll('.fooBar'); // scrolls smoothly to the element with the class of fooBar +``` From 1257cc418aa4381b836d5f133d30e053fb22666a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Fri, 2 Mar 2018 17:23:09 +0100 Subject: [PATCH 2/4] update smoothScroll, ES6 fix --- snippets/smoothScroll.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/snippets/smoothScroll.md b/snippets/smoothScroll.md index 0e3d3aa94..9165715d2 100644 --- a/snippets/smoothScroll.md +++ b/snippets/smoothScroll.md @@ -5,7 +5,7 @@ Smoothly scrolls the element on which it's called into the visible area of the b Use `.scrollIntoView` method to scroll the element. Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly. ```js -const smoothScroll = (element) => +const smoothScroll = element => document.querySelector(element).scrollIntoView({ behavior: 'smooth' }); From 0a480774dcad38083f873240836029055d809c5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Feje=C5=A1?= Date: Fri, 2 Mar 2018 17:24:20 +0100 Subject: [PATCH 3/4] update tag database --- tag_database | 1 + 1 file changed, 1 insertion(+) diff --git a/tag_database b/tag_database index 1674e3730..a50d43b54 100644 --- a/tag_database +++ b/tag_database @@ -229,6 +229,7 @@ shuffle:array,random similarity:array,math size:object,array,string sleep:function,promise +smoothScroll:browser,css sortCharactersInString:string sortedIndex:array,math sortedIndexBy:array,math,function From 1b8a298d04a9b317a90f7d2300fd395fe1dbf75c Mon Sep 17 00:00:00 2001 From: Angelos Chalaris Date: Sat, 3 Mar 2018 14:41:49 +0200 Subject: [PATCH 4/4] Update smoothScroll.md --- snippets/smoothScroll.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/snippets/smoothScroll.md b/snippets/smoothScroll.md index 9165715d2..de024bf68 100644 --- a/snippets/smoothScroll.md +++ b/snippets/smoothScroll.md @@ -2,7 +2,8 @@ Smoothly scrolls the element on which it's called into the visible area of the browser window. -Use `.scrollIntoView` method to scroll the element. Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly. +Use `.scrollIntoView` method to scroll the element. +Pass `{ behavior: 'smooth' }` to `.scrollIntoView` so it scrolls smoothly. ```js const smoothScroll = element => @@ -12,6 +13,6 @@ const smoothScroll = element => ``` ```js -smoothScroll('#fooBar'); // scrolls smoothly to the element with the id of fooBar -smoothScroll('.fooBar'); // scrolls smoothly to the element with the class of fooBar +smoothScroll('#fooBar'); // scrolls smoothly to the element with the id fooBar +smoothScroll('.fooBar'); // scrolls smoothly to the first element with a class of fooBar ```