From 0e8e59ac104b00e8c0a093357894053621bf0d25 Mon Sep 17 00:00:00 2001 From: Arunvel Sriram Date: Mon, 27 May 2019 00:22:46 +0530 Subject: Smooth scroll to contact section --- static/js/main.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/static/js/main.js b/static/js/main.js index 41ca242..8f9bb0c 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -37,6 +37,15 @@ menuBtn.click(function(){ } }); +function scrollTo(target) { + const top = $(target).offset().top; + const duration = 500; + const changeHash = function() { + location.hash = target + }; + $("html, body").animate({ scrollTop: top }, duration, changeHash); +} + $(document).ready(function(){ var elements = $(".sidebar > .main-info *"); @@ -52,4 +61,9 @@ $(document).ready(function(){ $(".main-content").addClass("active"); }, 1900); + $("#sidebar a.btn[href='#contact']").on("click", function (event) { + event.preventDefault(); + + scrollTo($.attr(this, "href")); + }); }); \ No newline at end of file -- cgit v1.2.3