Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. // SASS
  2.  
  3. /**
  4. * Top link
  5. * --------
  6. */
  7.  
  8. $mobile-size: 40px;
  9. $desktop-size: 50px;
  10. $mobile-offset: 20px;
  11. $desktop-offset: 40px;
  12. $default-color: #333;
  13. $hover-color: #000;
  14.  
  15. .to-top {
  16. background-color: $default-color;
  17. background-image: url('arrow');
  18. background-position: center 10px;
  19. background-repeat: no-repeat;
  20. background-size: 20px;
  21. bottom: $mobile-offset;
  22. cursor: pointer;
  23. height: $mobile-size;
  24. line-height: $mobile-size;
  25. opacity: 0;
  26. pointer-events: none;
  27. position: fixed;
  28. right: $mobile-offset;
  29. text-align: center;
  30. transition: all 0.5s ease-in-out;
  31. width: $mobile-size;
  32. z-index: 1;
  33. }
  34.  
  35. @media(min-width: 1001px) {
  36. .to-top {
  37. background-position: center 15px;
  38. background-size: 20px;
  39. bottom: $desktop-offset;
  40. height: $destkop-size;
  41. line-height: $destkop-size;
  42. right: $desktop-offset;
  43. width: $destkop-size;
  44. }
  45. }
  46.  
  47. .to-top:hover {
  48. background-color: $hover-color;
  49. }
  50.  
  51. .show-to-top .to-top {
  52. opacity: 1;
  53. pointer-events: auto;
  54. }
  55.  
  56. // JQUERY
  57.  
  58. /**
  59. * Top link
  60. * --------
  61. */
  62.  
  63. // [1] where to jump to
  64. // [2] point from where to show link
  65.  
  66. // append link
  67. $('body').append('<a class="to-top" title="Terug naar boven" href="[1]"></a>');
  68.  
  69. // smooth scroll to top of page
  70. $('.to-top').on('click', function(event) {
  71. event.preventDefault();
  72.  
  73. $('html, body').animate({
  74. scrollTop: $($.attr(this, 'href')).offset().top
  75. }, 500);
  76. });
  77.  
  78. // check offset top
  79. function checkOffset() {
  80. requestAnimationFrame(checkOffset);
  81.  
  82. if($(window).scrollTop() > $('[2]').height()) {
  83. $('body').addClass('show-to-top');
  84. } else {
  85. $('body').removeClass('show-to-top');
  86. }
  87. }
  88.  
  89. requestAnimationFrame(checkOffset);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement