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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:30:27+00:00 2026-06-13T14:30:27+00:00

So I am making a little game where you have to press Ctrl to

  • 0

So I am making a little game where you have to press Ctrl to stop a div from jumping randomly.
However I can’t get it working…
The jumpRandom function works fine, until i put the randomJump(){return false;}; inside the if (event.ctrlKey) {}. What should I do to get it working?

js:

    $(document).ready(function() {

function randomFromTo(from, to){
            return Math.floor(Math.random() * (to - from + 1) + from);
}
$( "#goal" ).bind('mouseenter keypress', function(event) {
    if (event.ctrlKey) {
            randomJump(){return false;};
        }
});
$('#goal').mouseenter(randomJump);

function randomJump(){
            /* get Window position and size
             * -- access method : cPos.top and cPos.left*/
            var cPos = $('#pageWrap').offset();
            var cHeight = $(window).height() - $('header').height() - $('footer').height();
            var cWidth = $(window).width(); 

            // get box padding (assume all padding have same value)
            var pad = parseInt($('#goal').css('padding-top').replace('px', ''));

            // get movable box size
            var bHeight = $('#goal').height();
            var bWidth = $('#goal').width();

            // set maximum position
            maxY = cPos.top + cHeight - bHeight - pad;
            maxX = cPos.left + cWidth - bWidth - pad;

            // set minimum position
            minY = cPos.top + pad;
            minX = cPos.left + pad;

            // set new position         
            newY = randomFromTo(minY, maxY);
            newX = randomFromTo(minX, maxX);


            $('#goal').fadeOut(50, function(){

                $('#goal').fadeIn(700);
            });
            $('#goal').animate({
                    left: newX,
                    top: newY,
                    duration: 500
                });
        }
});
  • 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-13T14:30:29+00:00Added an answer on June 13, 2026 at 2:30 pm

    Try this:

    $("#goal").bind('mouseenter keypress', function (e) {
        randomJump(e);
    });
    
    function randomJump(e) {
        if (!e.ctrlKey) {
            //do normal stuff
        } else {
            //depending on how permanent you need this to be...
            //$("#goal").unbind('mouseenter keypress');
        }
        return !e.ctrlKey;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making a basic little game in Java and I want to have
I'm making a little iphone game, and I would get some clues. Let's imagine:
I'm making a little voting tool (voting from 1 to 5) and I have
I am making a little game in WPF to understand it better, I have
So, I'm making this little game where you have a flashlight. The flashlight is
I'm making a simple WP7 game and I have a little problem with orientation
I'm making a little java game in which I would have two threads (well
I'm currently making a little game with a countdown timer. I use an NSTimer,
I'm having some difficulties with the following problem: I'm making a little game where
While making a little Pong game in C++ OpenGL, I decided it'd be fun

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.