Created
December 17, 2018 12:14
-
-
Save rochabianca/15f1e5a0a4a2b418369c773699bc85a1 to your computer and use it in GitHub Desktop.
slower and way more cool scroll to an section in the page. It needs jQuery
This file contains 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | |
<title>Document</title> | |
</head> | |
<body> | |
<a href="#reference" class="styled-down">Click Me</a> | |
<!-- Pretend that is a very long scroll here --> | |
<div id="reference">Wow! You just got here! </div> | |
</body> | |
</html> |
This file contains 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
$(document).on("click", ".styled-down", function(e) { | |
e.preventDefault(); | |
var id = $(this).attr("href"), | |
menuHeight = $(".menu").innerHeight(); | |
targetOffset = $(id).offset().top; | |
$("html, body").animate( | |
{ | |
scrollTop: targetOffset - menuHeight | |
}, | |
1000 | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment