Last active
January 20, 2017 17:22
-
-
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
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
| <!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> |
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 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