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 7785283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:13:52+00:00 2026-06-01T20:13:52+00:00

I have a script that manually preloads all images that will be required. It

  • 0

I have a script that manually preloads all images that will be required. It looks like this:

<script type="text/javascript">
(new Image()).src = "/images/buttonpinkpressed.png";
(new Image()).src = "/images/smallbuttonpinkpressed.png";
</script>

Actually, there is a lot of such entries for every type of button and other elements. The worst of all is that the project is in progress and new buttons are being added daily, so it’s easy to forget add them to the list.

Now I want to use one universal script that preloads everything in use.

It should enumerates all elements with a jQuery-like selector (say, $(‘buttons’) to get all buttons) in the document, then – and this is the hardest part to me – find the style which is the result of the element’s class and ‘active’ class (not to be confused with :active pseudoclass, though, there should not be any difference).

For instance, there is a button:

<button type="button" class="small pink"><p>Menu</p></button>

And there is the following CSS:

button.pink.large
{
    background-image: url('buttonpinknormal.png');
}
button.pink.large.active
{
    background-image: url('buttonpinkpressed.png');
}
button.pink.small
{
    background-image: url('buttonpinksmallnormal.png');
}
button.pink.small.active
{
    background-image: url('buttonpinksmallpressed.png');
}

Obviously, for this button the preloaded image should be the last one, since ‘small’ and ‘pink’ are explicitly defined and ‘active’ is what we are looking for:

button.pink.small.active
{
    background-image: url('buttonpinksmallpressed.png');
}

So, the question is how to filter the styles.

Regards,

UPDATE

As you can see, initially the button has no ‘active’ style. It’s being added with a script on touch event (because Android Webkit doesn’t support real :active). That’s why the image should be preloaded from another script. And, yes, I see run-time loading of active-state images on click, it looks UGLY.

  • 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-06-01T20:13:53+00:00Added an answer on June 1, 2026 at 8:13 pm

    Use a sprite and just change the background-position, that way the browser only has to do 1 request, and you won’t have to do a preload since the normal state should be visible. And, switching between states is lightening fast since its just re-positioning the rendered image (not that separate images is slow, just that it is less efficient)

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

Sidebar

Related Questions

I have a script that will convert a text file into a resource file,
I have a script that generates images from text using PHP. It's working fine
I have this script that basically will show a product or products based on
I have this script in BASH (linux) shells script that adds all *.jar files
I have a script that may be run manually or may be run by
I have a script that works fine when I run it manually in R
I have a perl script that is inserting records from a text file into
I have a vb script that processes text files on a server, however, very
I have a python script that converts images and videos withing a directory. The
I'd like to have a script that shows the users who are logged in

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.