www.webdeveloper.com
Results 1 to 12 of 12

Thread: [RESOLVED] showing when everythings is loaded...

  1. #1
    Join Date
    Aug 2012
    Posts
    43

    resolved [RESOLVED] showing when everythings is loaded...

    am i eight that this is a good way to make sure the page only show when everything is loaded? (also images etc)?
    (given that #main is the div holding al the content...)
    Code:
    $(document).ready(function(){
    	$('#main').hide();
    	$(window).load(function(){
    		$('#main').show();
    	});
    });
    thanks for you <input>

    S
    When the only tool you have is a hammer, everything looks like a nail.

  2. #2
    Join Date
    Mar 2009
    Posts
    452
    no

  3. #3
    Join Date
    Aug 2012
    Posts
    43
    Some more info if you want
    Thanks
    When the only tool you have is a hammer, everything looks like a nail.

  4. #4
    Join Date
    Mar 2009
    Posts
    452
    actually the $(document).ready will run after the page has been loaded completely.


    another way is to hide your #main is to hide it with css and then show via jQuery when document is ready.

    #main {display: none;}

    in your stylesheet or in you head will tell your browser to hide it even before the #main is loaded actually.

  5. #5
    Join Date
    Aug 2012
    Posts
    43
    $(window).load runs after $(document).ready :-)


    #main {display: none;} in combination with

    $(document).ready(function(){
    $(window).load(function(){
    $('#main').show();
    });
    });

    should be fine...
    When the only tool you have is a hammer, everything looks like a nail.

  6. #6
    Join Date
    Mar 2009
    Posts
    452
    actually i m talking about the events, ready event is fired after load event has done, so if you simply omit $(window).load(function() and leave it as follows, it will work fine too

    $(document).ready(function(){
    $('#main').show();
    });

  7. #7
    Join Date
    Aug 2012
    Posts
    43
    ah maybe i'm mis informed, but willing to learn.
    here is where i got some info:

    The window load event executes a bit later (after document ready) when the complete page is fully loaded, including all frames, objects and images. Therefore functions which concern images or other page contents should be placed in the load event for the window or the content tag itself.
    from http://4loc.wordpress.com/2009/04/28...vs-windowload/
    When the only tool you have is a hammer, everything looks like a nail.

  8. #8
    Join Date
    Aug 2012
    Posts
    43
    Quote Originally Posted by ZABI View Post
    $(document).ready(function(){
    $('#main').show();
    });
    would show the #main even if images are not yet loaded...
    When the only tool you have is a hammer, everything looks like a nail.

  9. #9
    Join Date
    Nov 2010
    Posts
    1,036
    agree with Nomistake - it's not like it's a complicated thing to test:
    Code:
    <script type="text/javascript">
    
    $(document).ready(function(){
    	$(window).load(function(){
    		alert("ready");//alerts after the image is loaded
    	});
    });
    </script>
    
    </head>
    <body>
    <img src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Nokota_Horses_cropped.jpg/250px-Nokota_Horses_cropped.jpg"></img>
    
    </body>
    compare to:
    Code:
    <script type="text/javascript">
    
    $(document).ready(function(){
    	alert("ready");//alerts before the image is loaded
    });
    </script>
    
    </head>
    <body>
    <img src="http://upload.wikimedia.org/wikipedia/commons/thumb/d/de/Nokota_Horses_cropped.jpg/250px-Nokota_Horses_cropped.jpg"></img>
    
    </body>

  10. #10
    Join Date
    Jan 2011
    Location
    United Kingdom, London
    Posts
    117
    $(document).ready() is fired when DOM is ready and not all content loaded. It usefull in most cases when developer just want to manipulate DOM, window.load should be your solution
    Javascript, jQuery / Prototype & PHP expert ready to complete your work on Freelancer.co.uk - Hire Me at https://www.freelancer.co.uk/users/1...&action=hireme

  11. #11
    Join Date
    Mar 2009
    Posts
    452
    Great, hmm interesting... will try to find out more.

  12. #12
    Join Date
    Aug 2012
    Posts
    43
    Thank you all for your responses,
    i thing all is clear now :-)
    S
    When the only tool you have is a hammer, everything looks like a nail.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles