Skip to content

Instantly share code, notes, and snippets.

@ccurtin
Last active October 7, 2016 17:52
Show Gist options
  • Select an option

  • Save ccurtin/0e7318f47b4698190688 to your computer and use it in GitHub Desktop.

Select an option

Save ccurtin/0e7318f47b4698190688 to your computer and use it in GitHub Desktop.
Scroll to a target ID on a different page.
// 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);
#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