Last active
August 24, 2021 12:14
-
-
Save IgorGavrilenko/5f816a5c3661bbd6128041d64b3d0f6d to your computer and use it in GitHub Desktop.
scroll_to_element
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
| $(function() { | |
| // scroll_to_element | |
| var scrollToElement = function (toggle, anchor) { | |
| $(toggle).click(function(e) { | |
| e.preventDefault(); | |
| $('html, body').animate({ | |
| scrollTop: $(anchor).offset().top | |
| }, 1000); | |
| }); | |
| } | |
| scrollToElement('.toggle-1', '.anchor-1'); | |
| scrollToElement('.toggle-2', '.anchor-2'); | |
| scrollToElement('.toggle-3', '.anchor-3'); | |
| scrollToElement('.toggle-4', '.anchor-4'); | |
| scrollToElement('.toggle-5', '.anchor-5'); | |
| scrollToElement('.toggle-6', '.anchor-6'); | |
| }); | |
| (function (){ | |
| var $jqToggle = $('.jq-toggle'); | |
| var $root = $('html, body'); | |
| var $animDl = 250; | |
| var $attr = 'href'; | |
| if ($jqToggle.length) { | |
| $jqToggle.on('click', function(e){ | |
| var $anchor = $(this); | |
| $root.stop().animate({ | |
| scrollTop: $($anchor.attr($attr)).offset().top-100 | |
| }, $animDl); | |
| e.preventDefault(); | |
| return false; | |
| }); | |
| } | |
| }()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment