Guest User

Untitled

a guest
Jun 24th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. {% comment %}
  2. Reduce below value if you need the back to the top button to appear higher up on the page.
  3. That value is in pixels.
  4. {% endcomment %}
  5. {% assign vertical_offset_for_trigger = 300 %}
  6. {% comment %}
  7. Vertical offset from bottom of browser for the position of the button.
  8. {% endcomment %}
  9. {% assign position_from_bottom = '15em' %}
  10.  
  11. <a href="#" title="Back to the top" class="back-to-top">
  12. <span>Top</span> <i class="fas fa-angle-double-up"></i>
  13. </a>
  14. <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.0/css/all.css" integrity="sha384-lKuwvrZot6UHsBSfcMvOkWwlCMgc0TaWr+30HWe3a4ltaBwTZhyTEggF5tJv8tbt" crossorigin="anonymous">
  15.  
  16. <style>
  17. .back-to-top {
  18. position: fixed;
  19. bottom: {{ position_from_bottom }};
  20. right: 10px;
  21. text-decoration: none;
  22. color: #999;
  23. background-color: #eee;
  24. font-size: 16px;
  25. padding: 0.3em;
  26. display: none;
  27. -webkit-border-top-left-radius: 3px;
  28. -webkit-border-bottom-left-radius: 3px;
  29. -moz-border-radius-topleft: 3px;
  30. -moz-border-radius-bottomleft: 3px;
  31. border-top-left-radius: 3px;
  32. border-bottom-left-radius: 3px;
  33. z-index: 60000;
  34. }
  35. .back-to-top i {
  36. vertical-align: middle;
  37. }
  38. .back-to-top span {
  39. padding-left: 0.5em;
  40. }
  41. .back-to-top i + span {
  42. padding-left: 0;
  43. }
  44. .back-to-top:hover {
  45. text-decoration: none;
  46. color: #555;
  47. }
  48. </style>
  49.  
  50. <script>
  51. window.onload = function() {
  52. jQuery(function($) {
  53. var offset = {{ vertical_offset_for_trigger }};
  54. var duration = 500;
  55. $(window).scroll(function() {
  56. if ($(this).scrollTop() > offset) {
  57. $('.back-to-top').fadeIn(duration);
  58. }
  59. else {
  60. $('.back-to-top').fadeOut(duration);
  61. }
  62. });
  63. $('.back-to-top').unbind('click.smoothscroll').bind('click', function(e) {
  64. e.preventDefault();
  65. $('html, body').animate( { scrollTop: 0 }, duration);
  66. return false;
  67. })
  68. });
  69. }
  70. </script>
Add Comment
Please, Sign In to add comment