progressbar.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <style>
  2. /* Loading Progress Bar */
  3. #progress {
  4. position: absolute;
  5. z-index: 1000;
  6. top: 0px;
  7. left: -6px;
  8. width: 2%;
  9. opacity: 1;
  10. height: 2px;
  11. background: #1a1a1a;
  12. border-radius: 1px;
  13. transition: width 4s ease-out, opacity 400ms linear;
  14. }
  15. @-moz-keyframes bugfix { from { padding-right: 1px ; } to { padding-right: 0; } }
  16. </style>
  17. <script>
  18. // Page Loading Bar
  19. window.loadStart = function(distance) {
  20. var distance = distance || 0;
  21. // only add progrstess bar if not already present
  22. if (django.jQuery("#loading-bar").length == 0) {
  23. django.jQuery("body").add("<div id=\"loading-bar\"></div>");
  24. }
  25. if (django.jQuery("#progress").length === 0) {
  26. django.jQuery("body").append(django.jQuery("<div></div>").attr("id", "progress"));
  27. let last_distance = (distance || (30 + (Math.random() * 30)))
  28. django.jQuery("#progress").width(last_distance + "%");
  29. setInterval(function() {
  30. last_distance += Math.random()
  31. django.jQuery("#progress").width(last_distance + "%");
  32. }, 1000)
  33. }
  34. };
  35. window.loadFinish = function() {
  36. django.jQuery("#progress").width("101%").delay(200).fadeOut(400, function() {
  37. django.jQuery(this).remove();
  38. });
  39. };
  40. window.loadStart();
  41. window.addEventListener('beforeunload', function() {window.loadStart(27)});
  42. document.addEventListener('DOMContentLoaded', function() {window.loadFinish()});
  43. </script>