From f6866211ed7711b1ff42015aa2aac6ad05e5b18a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 13 Jun 2022 17:09:46 -0500 Subject: [PATCH] added js functionality to scroll to a target element --- public/js/main.js | 10 ++++++++++ views/index.ejs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/public/js/main.js b/public/js/main.js index fe434d7..3cf2323 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,3 +1,13 @@ +const scrollBtn = document.getElementById('contributors') +const targetScroll = document.getElementById('contributors-title') +const elemRect = targetScroll.getBoundingClientRect() +scrollBtn.addEventListener("click", function () { + window.scrollTo({ + top: elemRect.top, + left: 0, + }); +}); + const btn = document.getElementById('keyword-btn'); btn.addEventListener('click', getMatches); diff --git a/views/index.ejs b/views/index.ejs index 5948006..6f349c9 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -27,7 +27,7 @@