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

  • Home
  • SEARCH
  • 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 582851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:43:51+00:00 2026-05-13T14:43:51+00:00

I’m developing a simple web quiz and using javascript, I would like to create

  • 0

I’m developing a simple web quiz and using javascript, I would like to create an effect that displays a small image (1UP) that wanders around the “game deck” when users reach a specific level or score; user could gain an extra life simply clicking on it in time.

Do you know any Jquery plugin or javascript snippet to achieve an effect like this?

  • 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-13T14:43:51+00:00Added an answer on May 13, 2026 at 2:43 pm

    It’s actually surprisingly easy to do this:

    Create the element:

    img = document.createElement('img');
    

    Set its source:

    img.src = "myimage.png";
    

    Position it absolutely and such:

    img.style.position = "absolute";
    img.style.left = "50px";
    img.style.top = "50px";
    img.style.width = "50px";  // Make these match the image...
    img.style.height = "50px"; // ...or leave them off
    

    (Obviously, use whatever coordinates and size you want.)

    You may want to make sure it appears above other things:

    img.style.zIndex = 100; // Or whatever
    

    Add it to the document:

    document.body.appendChild(img);
    

    Move it around

    Use window.setInterval (or setTimeout depending on how you want to do it) to move it around by changing its style.left and style.top settings. You can use Math.random to get a random floating point number between 0 and 1, and multiply that and run it through Math.floor to get a whole number for changing your coordinates.

    Example

    This creates an image at 50,50 and animates it (in a very jittery random way; I didn’t spend any time making it look nifty) every fifth of a second for 10 seconds, then removes it:

    function createWanderingDiv() {
        var img, left, top, counter, interval;
    
        img = document.createElement('img');
    
        img.src = "myimage.png";
    
        left = 200;
        top  = 200;
        img.style.position = "absolute";
        img.style.left = left + "px";
        img.style.top = top + "px";
        img.style.width = "200px";  // Make these match the image...
        img.style.height = "200px"; // ...or leave them out.
    
        img.style.zIndex = 100; // Or whatever
    
        document.body.appendChild(img);
    
        counter = 50;
        interval = 200; // ms
        window.setTimeout(wanderAround, interval);
    
        function wanderAround() {
    
            --counter;
            if (counter < 0)
            {
                // Done; remove it
                document.body.removeChild(img);
            }
            else
            {
                // Animate a bit more
                left += Math.floor(Math.random() * 20) - 10;
                if (left < 0)
                {
                    left = 0;
                }
                top  += Math.floor(Math.random() * 10)  - 5;
                if (top < 0)
                {
                    top = 0;
                }
                img.style.left = left + "px";
                img.style.top  = top  + "px";
    
                // Re-trigger ourselves
                window.setTimeout(wanderAround, interval);
            }
        }
    }
    

    (I prefer re-scheduling on each iteration via setTimeout [as above] to using setInterval, but it’s totally your call. If using setInterval, remember the interval handle [return value from setInterval and use window.clearTimeout to cancel it when you’re done.)

    The above is raw DOM/JavaScript; jQuery offers some helpers to make it a bit simpler, but as you can see, it’s pretty straightforward even without.

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

Sidebar

Ask A Question

Stats

  • Questions 430k
  • Answers 430k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer It sounds to me as though you are saying that… May 15, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer You need to "unbox" the int value: int temp =… May 15, 2026 at 2:00 pm
  • Editorial Team
    Editorial Team added an answer References didn't exist in the language when this was created. May 15, 2026 at 2:00 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.