Results 1 to 3 of 3

Thread: Preloading background image in display: none objects

  1. #1
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Preloading background image in display: none objects

    I have the following in the stylesheet for my website:

    Code:
    #projects_menu
    {
    	position: absolute;
    	left: 98px;
    	top: 161px;
    	z-index: 1;
    	width: 102px;
    	height: 48px;
    	font-size: 11px;
    	overflow: hidden;
    	border-bottom: 1px solid #165117;
    	display: none;
    	background: url("dropdownbg.gif");
    }
    My question is, will that background image be preloaded, so that it appears instantly when I make the object visible, or do I need to use some javascript to preload it?

    If I do need to use javascript to preload it, is this all I need to do?

    Code:
    var dropdownbg = new Image(102, 59); dropdownbg.src = "dropdownbg.gif";
    Thanks!
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

  2. #2
    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

    Different browsers may handle that differently but most will load that image ahead of time, I think. Your preload code looks more than sufficient. However, since this is the css forum and css shouldn't be dependant upon javascript if it is avoidable, another way to 'preload' the image would be to have this right after your body tag:

    HTML Code:
    <img style="visibility:hidden;position:absolute;top:-1000px;left:-1000px;" src="dropdownbg.gif">
    That will ensure that the image gets cached as the first item on the page. You should also take whatever measures you can (cropping and/or optimization) to make sure that the image requires as few bytes as possible.
    - John
    ________________________

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

  3. #3
    Join Date
    Feb 2007
    Posts
    116
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by jscheuer1 View Post
    Different browsers may handle that differently but most will load that image ahead of time, I think. Your preload code looks more than sufficient. However, since this is the css forum and css shouldn't be dependant upon javascript if it is avoidable, another way to 'preload' the image would be to have this right after your body tag:

    HTML Code:
    <img style="visibility:hidden;position:absolute;top:-1000px;left:-1000px;" src="dropdownbg.gif">
    That will ensure that the image gets cached as the first item on the page. You should also take whatever measures you can (cropping and/or optimization) to make sure that the image requires as few bytes as possible.
    Great, thanks a lot.
    "Rock and roll ain't noise pollution." - AC/DC

    http://www.blake-foster.com

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
  •