Last active
October 7, 2016 17:52
-
-
Save ccurtin/0e7318f47b4698190688 to your computer and use it in GitHub Desktop.
Scroll to a target ID on a different page.
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
| // Scrolling to an ID on different page | |
| (function($) { | |
| $('body').bind('touchstart', function() {}); | |
| var jump = function(e) { | |
| if (e) { | |
| var target = $(this).attr("href"); | |
| } else { | |
| var target = location.hash; | |
| } | |
| // change if want to offset | |
| loc = 0; | |
| $('html,body').animate({ | |
| scrollTop: $(target).offset().top - loc | |
| }, 1000, function() { | |
| return false; | |
| location.hash = target; | |
| }); | |
| } | |
| $('html, body').hide() | |
| $(document).ready(function() { | |
| if (location.hash) { | |
| setTimeout(function() { | |
| $('html, body').scrollTop(0).show() | |
| jump() | |
| }, 0); | |
| } else { | |
| $('html, body').show() | |
| } | |
| }); | |
| })(jQuery); |
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
| #YOUR_ID:target { | |
| @include animation( fade 1s ease-in-out); | |
| @include animation-fill-mode(both); | |
| } | |
| @-webkit-keyframes fade { | |
| 0% { | |
| background-color: rgba(145, 141, 124,1); | |
| opacity:0; | |
| } | |
| 100% { | |
| background-color: rgba(145, 141, 124,0); | |
| opacity:1; | |
| } | |
| } | |
| @keyframes fade { | |
| 0% { | |
| background-color: rgba(145, 141, 124,1); | |
| opacity:0; | |
| } | |
| 100% { | |
| background-color: rgba(145, 141, 124,0); | |
| opacity:1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment