Hide page until everything is loaded Advanced

Anything done with jQuery will normally have to wait for document.ready, which is too late IMHO. Put a div on top, like so: <div id=”cover”></div> set some styles: #cover {position: fixed; height: 100%; width: 100%; top:0; left: 0; background: #000; z-index:9999;} and hide it with JS when all elements are loaded: $(window).on(‘load’, function() { $(“#cover”).hide(); … Read more

Requirejs domReady plugin vs Jquery $(document).ready()?

It seems like all the key points were already hit, but a few details fell through the cracks. Mainly: domReady It is both a plugin and a module. If you include it in the the requirements array w/ a trailing ! your module won’t execute until it’s “safe” to interact w/ the DOM: define([‘domReady!’], function … Read more

How can I run a directive after the dom has finished rendering?

It depends on how your $(‘site-header’) is constructed. You can try to use $timeout with 0 delay. Something like: return function(scope, element, attrs) { $timeout(function(){ $(‘.main’).height( $(‘.site-header’).height() – $(‘.site-footer’).height() ); }); } Explanations how it works: one, two. Don’t forget to inject $timeout in your directive: .directive(‘sticky’, function($timeout)

Is $(document).ready necessary?

Is $(document).ready necessary? no if you’ve placed all your scripts right before the </body> closing tag, you’ve done the exact same thing. Additionally, if the script doesn’t need to access the DOM, it won’t matter where it’s loaded beyond possible dependencies on other scripts. For many CMS’s, you don’t have much choice of where the … Read more