Results 1 to 3 of 3

Thread: Javascript On Load Issue?

  1. #1
    Join Date
    Feb 2008
    Posts
    90
    Thanks
    3
    Thanked 2 Times in 2 Posts

    Default Javascript On Load Issue?

    Good Afternoon all,

    Currently I'm trying to manipulate the tutorial found here,
    http://flowplayer.org/tools/demos/overlay/index.html
    to better fit my needs.

    I've got basically everything I need thus far, except for the fact I want it to load when the page loads and not when a link is clicked. It seems the part i have to edit is located here:
    Code:
    $(document).ready(function() {
    
    $("a[rel]").overlay();
    });
    I've tried to put the above into a function to call it on body onload, but it doesn't give me what i want.

    Can anyone give me any advice on this?
    Thanks!

  2. #2
    Join Date
    Oct 2009
    Posts
    845
    Thanks
    14
    Thanked 189 Times in 188 Posts

    Default

    I havent tried it out, just wondering what would happen if you changed this part
    Code:
    .simple_overlay {
    	
    	/* must be initially hidden */
    	display:none;
    	
    	/* place overlay on top of other elements */
    	z-index:10000;
    	
    	/* styling */
    	background-color:#333;
    	
    	width:675px;	
    	min-height:200px;
    	border:1px solid #666;
    	
    	/* CSS3 styling for latest browsers */
    	-moz-box-shadow:0 0 90px 5px #000;
    	-webkit-box-shadow: 0 0 90px #000;	
    }
    the display:none can be changed to display: block; and i guess that would show the overlay on page load. Of course it wouldn't work to well if you have several overlay pictures on your page. I am just guessing so it might not work !

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    $(document).ready is like onload. Except images might not be fully loaded yet. Try:

    Code:
    $(document).ready(function() {
    
    $("a[rel]").overlay();
    $("a[rel]").eq(0).click();
    });
    That will activate the first a tag with a rel. If you have more than one, you may choose which one by using its zero based index. Like the second one would be eq(1), the third eq(2) and so on.

    If you want to wait a little longer, but there is still no guarantee that your display none image will be loaded (this only matters if there are images in the overlay):

    Code:
    $(window).load(function() {
    
    $("a[rel]").overlay();
    $("a[rel]").eq(0).click();
    });
    If you have just one, as azoomer says, it might work to just change the display property in the css to block as he suggests.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

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