website.js 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. (function () {
  2. document.addEventListener('DOMContentLoaded', function () {
  3. new bootstrap.Carousel('#screenshotCarousel', {
  4. interval: 4000,
  5. ride: 'carousel',
  6. wrap: true,
  7. });
  8. window.addEventListener('scroll', function () {
  9. const navbarBrand = document.querySelector('.navbar-brand');
  10. const navbar = document.querySelector('.navbar');
  11. const rect = navbar.getBoundingClientRect();
  12. if (rect.top + window.scrollY > 100) {
  13. navbar.classList.add('top-nav-collapse');
  14. navbarBrand.style.display = 'inline-block';
  15. } else {
  16. navbar.classList.remove('top-nav-collapse');
  17. navbarBrand.style.display = 'none';
  18. }
  19. });
  20. const getDocumentHeight = function () {
  21. return Math.max(
  22. document.body.clientHeight,
  23. document.body.offsetHeight,
  24. document.body.scrollHeight,
  25. document.documentElement.clientHeight,
  26. document.documentElement.offsetHeight,
  27. document.documentElement.scrollHeight
  28. );
  29. };
  30. Array.prototype.forEach.call(document.querySelectorAll('.page-scroll a'), function (el) {
  31. el.addEventListener('click', function (ev) {
  32. ev.preventDefault();
  33. Array.prototype.forEach.call(document.querySelectorAll('.page-scroll'), function (child) {
  34. child.classList.remove('active');
  35. });
  36. this.parentElement.classList.add('active');
  37. let hash = this.getAttribute('href');
  38. let endLocation = document.querySelector(hash).offsetTop;
  39. let startLocation = window.pageYOffset;
  40. let distance = endLocation - startLocation;
  41. let start, percentage, position;
  42. let timeLapsed = 0;
  43. function scrollAnimation(timestamp) {
  44. if (!start) {
  45. start = timestamp;
  46. }
  47. timeLapsed += timestamp - start;
  48. percentage = timeLapsed / parseInt(500, 10);
  49. percentage = percentage > 1 ? 1 : percentage;
  50. position = startLocation + distance * percentage * percentage;
  51. window.scrollTo(0, Math.floor(position));
  52. let currentLocation = window.pageYOffset;
  53. if (
  54. position == endLocation ||
  55. currentLocation == endLocation ||
  56. (startLocation < endLocation && window.innerHeight + currentLocation) >= getDocumentHeight()
  57. ) {
  58. window.location.hash = hash;
  59. return;
  60. }
  61. window.requestAnimationFrame(scrollAnimation);
  62. start = timestamp;
  63. }
  64. window.requestAnimationFrame(scrollAnimation);
  65. });
  66. });
  67. });
  68. })();