__loading__.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. pc.script.createLoadingScreen(function (app) {
  2. var showSplash = function () {
  3. // splash wrapper
  4. var wrapper = document.createElement('div');
  5. wrapper.id = 'application-splash-wrapper';
  6. document.body.appendChild(wrapper);
  7. // splash
  8. var splash = document.createElement('div');
  9. splash.id = 'application-splash';
  10. wrapper.appendChild(splash);
  11. splash.style.display = 'none';
  12. var logo = document.createElement('img');
  13. //logo.src = 'https://s3-eu-west-1.amazonaws.com/static.playcanvas.com/images/play_text_252_white.png';
  14. logo.src = 'http://video.cgaii.com/new4dage/images/images/logo.svg';
  15. splash.appendChild(logo);
  16. logo.onload = function () {
  17. splash.style.display = 'block';
  18. };
  19. var container = document.createElement('div');
  20. container.id = 'progress-bar-container';
  21. splash.appendChild(container);
  22. var bar = document.createElement('div');
  23. bar.id = 'progress-bar';
  24. container.appendChild(bar);
  25. };
  26. var hideSplash = function () {
  27. var splash = document.getElementById('application-splash-wrapper');
  28. splash.parentElement.removeChild(splash);
  29. };
  30. var setProgress = function (value) {
  31. var bar = document.getElementById('progress-bar');
  32. if(bar) {
  33. value = Math.min(1, Math.max(0, value));
  34. bar.style.width = value * 100 + '%';
  35. }
  36. };
  37. var createCss = function () {
  38. var css = [
  39. 'body {',
  40. ' background-color: #283538;',
  41. '}',
  42. '#application-splash-wrapper {',
  43. ' position: absolute;',
  44. ' top: 0;',
  45. ' left: 0;',
  46. ' height: 100%;',
  47. ' width: 100%;',
  48. ' background-color: #283538;',
  49. '}',
  50. '#application-splash {',
  51. ' position: absolute;',
  52. ' top: calc(50% - 28px);',
  53. ' width: 264px;',
  54. ' left: calc(50% - 132px);',
  55. '}',
  56. '#application-splash img {',
  57. ' width: 100%;',
  58. '}',
  59. '#progress-bar-container {',
  60. ' margin: 20px auto 0 auto;',
  61. ' height: 2px;',
  62. ' width: 100%;',
  63. ' background-color: #1d292c;',
  64. '}',
  65. '#progress-bar {',
  66. ' width: 0%;',
  67. ' height: 100%;',
  68. ' background-color: #f60;',
  69. '}',
  70. '@media (max-width: 480px) {',
  71. ' #application-splash {',
  72. ' width: 170px;',
  73. ' left: calc(50% - 85px);',
  74. ' }',
  75. '}'
  76. ].join("\n");
  77. var style = document.createElement('style');
  78. style.type = 'text/css';
  79. if (style.styleSheet) {
  80. style.styleSheet.cssText = css;
  81. } else {
  82. style.appendChild(document.createTextNode(css));
  83. }
  84. document.head.appendChild(style);
  85. };
  86. createCss();
  87. showSplash();
  88. app.on('preload:end', function () {
  89. app.off('preload:progress');
  90. });
  91. app.on('preload:progress', setProgress);
  92. app.on('start', hideSplash);
  93. });