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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:19:49+00:00 2026-06-18T14:19:49+00:00

I am coding a JavaScript game, with a moving ball. I want an alert

  • 0

I am coding a JavaScript game, with a moving ball.
I want an alert message when the user manage to click on the moving ball.
It is working right now, but the event is not firing every times. It looks like the ball is moving too fast for the js engine to be able to notice that the ball was indeed clicked.
I am testing on Firefox 18, Windows 7 on a 5 years old cpu.

Here are some bits of my code :

myBall = document.getElementById("myBall");
function move(){
    myLeft += 20;
    myBall.style.left = myLeft + "px";
}    
myTimer = window.setInterval(move, 10);
...
myBall.addEventListener("click", function(){alert("win")});

Is there any way to set a click event listener on a small moving target, that will behave more accurately ? Would jQuery make any difference here?

  • 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-18T14:19:50+00:00Added an answer on June 18, 2026 at 2:19 pm

    All right, to solve the problem you’re having, you’ll need to add event listener for mousedown instead of click.

    It is because click requires mouse button to go both down and up, and – as @techfoobar noted – it must be done at the same place on the target element (if coords of mousedown and mouseup are not equal, the click event won’t be fired). The ball simply moves too fast to meet the aforementioned condition, hence the problem.

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

Sidebar

Related Questions

I'm coding up a page where I only want to use raw JavaScript code
I am coming from Java and try to learn Javascript right now. Doing that
I want to create iPhone app using phonegap Cordova 2.0. Now i wrote Javascript
I'm coding a JavaScript client to a REST JSON API. Since I don't want
I'll soon be coding some JavaScript in Adobe Acrobat Pro, but I hate coding
I'm coding a tile based game in javascript using canvas and was wondering how
I am quite experienced with coding in Javascript, but there's still one thing I
am new to coding in javascript and am presently working on a web page
I'm currently using a JavaScript coding style based on Douglas Crockford's Code Conventions for
I am new to Javascript coding and have looked for this information in many

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.