Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3438170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:09:16+00:00 2026-05-18T08:09:16+00:00

I just wrote a js code for a slideshow, using only one image (sprite).

  • 0

I just wrote a js code for a slideshow, using only one image (sprite). With js I’m changing the background position to change the visible image.

var first = true;
function galesprite() {
  if (first) {
    var bg_pos = '0px 0px';
    first = false;
  } else {
    var bg_pos = $("#gmap").css('background-position');
  }

  /* Sub función para cuando termine la animación de fadeOut, sinó la foto se 
   * cambia antes y no crea el efecto deseado. */
  $("#gmap").fadeOut(1000, function() {
    var xy = bg_pos.split(' ');
    var y = xy[1].split('px');
    var newy = parseInt(y) + 200;
    var bgpos = xy[0] + ' ' + newy + 'px';
    $('#gmap').css('background-position', bgpos);
    $("#gmap").fadeIn(1000);
    setTimeout('galesprite()', 4000);
  });
}

And the html affected is this. With a css class that puts the background image, a set of vertical images. Each image has 200px height.

<div id="gmap"></div>

#gmap {
    height: 200px;
    width: 270px;
    background-image: url('../images/diapositiva-home/surf.jpg');
    background-position: 0px 0px;
}

What I do is loop periodicaly increasing the background Y position for the div. So it seems that changes the image.
The idea is minimize the loading time of the page using the sprite instead of loading 10 images.
Do you see anything I could improve? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:09:17+00:00Added an answer on May 18, 2026 at 8:09 am

    Sprites are best for small icons – not large galleries.

    If you have a 600kb sprite, then you won’t be able to show the first image until the whole thing has downloaded (with exception).

    I generally avoid sprites for large JPEGs, and simply do a…

    var img = new Image();
    
    img.onload = function() {
       // Loaded, we can now show the next image
    }
    
    img.src = 'bob.jpg'; 
    

    This means you can download the next image whilst showing the current one, and switch to it when you know it has finished downloading.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Question: I have just wrote my first code using c# lambda expressions. It works,
I just wrote a piece of CPP code and I compiled it using G++
I just wrote this code to generate an image <?php $canvas = imagecreatetruecolor(800, 350);
I just wrote some code to test the behavior of std::equal, and came away
I just wrote this code to convert a GUID into a byte array. Can
I just wrote a simple code where I want a textfield and a button
I just wrote some NIO-code and wonder how to stress-test my implementation regarding SocketChannel.write(ByteBuffer)
I just wrote some .NET code to get connection string from the config file.
I just wrote this piece of code but I'm not quite happy about it.
I just wrote perhaps the ugliest bit of MVC code in existence. It is:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.