SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast Pure L's Avatar
    Join Date
    Oct 2007
    Posts
    47
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    calling an image sprite via javascript

    Hi.

    I'd like to lessen the calls to the server on some graphics I'm using (a couple of 11x11 gifs which are a "+" and "-" for an accordion menu/nav).

    Currently, I'm just calling each image which results in a slight lag (hardly noticeable but enough that it bugs me).

    I bolded the places where I'm calling the images. I'd like to do an inline call to the sprite from the script (since that only loads the image once, correct?)....Something like this:background:transparent url(images/sprites.gif) no-repeat scroll 100% -107px;

    (I'm also using Prototype...just so you know):
    Code:
     Event.observe(window, 'load', function() {
            $('nav-personal-groups-toggler').show();
            $('nav-personal-groups-listener').update('<img src="images/minus.gif" alt="" />');
            Event.observe('nav-personal-groups-listener', 'click', function(){
                $('nav-personal-groups-toggler').toggle();
                if($('nav-personal-groups-toggler').visible()){
                    $('nav-personal-groups-listener').update('<img src="images/minus.gif" alt="" />');
                } else {
                    $('nav-personal-groups-listener').update('<img src="images/plus.gif" alt="" />');
                }
            });
        });
    Any advice? Thanks!

  2. #2
    We're from teh basements.
    Join Date
    Apr 2007
    Posts
    1,205
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Web browsers cache images that never change, so they're only retrieved from the server once to begin with. I have noticed some flaky behavior in this regard where earlier versions of Firefox were concerned, but that has supposedly been fixed in FF3.


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
  •