Answer the question
In order to leave comments, you need to log in
How to make a global preloader in Angular 2?
Actually a simple situation. I have a global preloader that needs to be shown while the angular2 framework is loading. It uses gif. But at some point, the GIF freezes for a second and then the application itself appears. I would like to somehow catch this moment and make a beautiful disappearance of the element.
html:
<body>
<app-root>
<style>
body {
background: #002538;
}
.gif-preloader {
position: absolute;
top: 50%;
left: 50%;
transform: translate3d(-50%, -50%, 0);
-webkit-transform: translate3d(-50%, -50%, 0);
-moz-transform: translate3d(-50%, -50%, 0);
-ms-transform: translate3d(-50%, -50%, 0);
margin: 0 auto;
-webkit-transition: opacity .3s ease-in-out;
-moz-transition: opacity .3s ease-in-out;
-ms-transition: opacity .3s ease-in-out;
-o-transition: opacity .3s ease-in-out;
transition: opacity .3s ease-in-out;
}
#preloader.fade {
opactity: 0;
}
</style>
<img src="/assets/preloader2.gif" width="66px" height="66px" class="gif-preloader" id="preloader">
</app-root>
</body>
export class MainModule {
constructor() {
document.getElementById("preloader").classList.add("fade");
}
}
Answer the question
In order to leave comments, you need to log in
Alternatively, make the preloader not in the application tag, but in a separate one. We initially hide the application tag, we hang the DOMNodeInserted handler on it - when the content is inserted, the callback will be executed.
element.addEventListener("DOMNodeInserted", function (ev) {
// скрываем анимацию
// показываем приложение
// удаляем тег прелоадера
}, false);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question