Skip to content

Instantly share code, notes, and snippets.

@Nicklas2751
Last active January 20, 2017 17:22
Show Gist options
  • Select an option

  • Save Nicklas2751/04bdbb26aea2e9e46672e0a43e244594 to your computer and use it in GitHub Desktop.

Select an option

Save Nicklas2751/04bdbb26aea2e9e46672e0a43e244594 to your computer and use it in GitHub Desktop.
A javascript snippet from nicklas.wiegandt.eu to enable a scroll to top via link
<!DOCTYPE html>
<html>
<head>
<script src='js/mainscript.js'></script>
<title>Nicklas Wiegandt Contact</title>
</head>
<body>
...
<div id="0"></div>
...
<div id="toplink">
<a href="#0"><span class="glyphicon glyphicon-arrow-up"></span><br/>
Back to top</a>
</div>
</body>
</html>
function setdefaults()
{
$("#toplink").css("opacity",0);
}
$(document).ready(function(){
setdefaults();
$(window).scroll(function() {
$scrolled = $(window).scrollTop();
$toScrollPercentage = 50;
$toScroll = $(window).height()*($toScrollPercentage/100);
if($scrolled < $toScroll)
{
$("#toplink").css("opacity",0);
} else
{
$("#toplink").css("opacity",0.5);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment