I have a really simple Html web site (No server side code). Instead of replicate some HTML, I decided to use angularJs. Using some directives and some partial views, I could re-use some code without replicate it.
I created a directive for preloader, but I have a problem.. The preloader is shown a bit later than the loading of the page... What I mean is that some images and text are loaded, then the preloader appear, and finally when the document is ready the preloader disappear... It's really annoying!!
I would like that the preloader appeared immediately before of everything, but perhaps in that moment angular has not been loaded yet. I don't know If I am clear.
In any case, here you can see what I mean:
Here my code:
HTML PAGE
<head>
...
<script src="/js/angularjs-1.4.8.min.js"></script>
<script src="/js/angularjs/app.js"></script>
<script src="/js/angularjs/directives/preloader.js"></script>
</head>
<body ng-app="renovahaus">
<rh-preloader></rh-preloader>
...
</body>
JS - DIRECTIVE
angular.module('renovahaus')
.directive('rhPreloader', ['$document', function ($document) {
return {
restrict: 'E',
replace: true,
templateUrl: '/partial_views/directives/templates/preloader.html',
link: function (scope, element, attr) {
$document.ready(function () {
/*will first fade out the loading animation*/
$(element).find("#status").fadeOut();
/*will fade out the whole DIV that covers the website.*/
$(element).delay(1000).fadeOut("slow");
$("body").css('overflow-y', 'visible');
$("body").css('position', 'relative');
});
}
};
}]);
HTML - TEMPLATE DIRECTIVE
<div class="preloader">
<div id="status"></div>
<div id="loading-center">
<div id="loading-center-absolute">
<div class="object" id="object_four"></div>
<div class="object" id="object_three"></div>
<div class="object" id="object_two"></div>
<div class="object" id="object_one"></div>
</div>
</div>
</div>
thank you