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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:05:51+00:00 2026-06-13T06:05:51+00:00

In my code i’m trying to compare the height with the position of an

  • 0

In my code i’m trying to compare the height with the position of an element, to ensure that the element doesn’t leave the game’s div.

First I get the position of my element, snake. and if the cursor is too close then i move it. Then at the end I do a check that it is at least 20 pixels away from the top and bottom. For some reason everything is working except the when it reaches the bottom of the screen (which is the else if statement in the end block of code)

var posL = $("#snake").position().left;
var posT = $("#snake").position().top;
if((e.pageX-200 < posL) && (posL < e.pageX-50)){
  if(posL > 20){
    posL = posL - 5;
  }else{
    posT = posT + 5;
  }

…

if(posT < 20){
  posT = 20;
}else if(posT > parseInt($("#game").height)){
  posT = parseInt($("#game").height) - 20;
}
  • 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-13T06:05:52+00:00Added an answer on June 13, 2026 at 6:05 am

    You forgot the () after .height …twice! 😉

    if(posT < 20) {
       posT = 20;  // ------------------------v
    } else if(posT > parseInt($("#game").height)){
       posT = parseInt($("#game").height) - 20;
    }              // -----------------^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Code in here: jsfiddle Demo I wanna to get the div#content height when it
Code first. This is what I'm trying to do. I'm close, but I think
Code: <?php //initializing script, do not modify session_start(); define('IN_SCRIPT', true); //so that global.php cannot
Code: $exchangesnapin = Add-PSSnapin Microsoft.Exchange.Management.PowerShell.E2010; $output = shell_exec('powershell '.$exchangesnapin.';get-mailboxdatabase 2>&1'); echo( '<pre>' ); echo(
Basically, what I'm trying to create is a page of div tags, each has
Code for webpage such that if anyone closes it, then next time when he
Code: # it's an ajax request, so parameters are passed via GET method def
Code duplication is usually bad and often quite easy to spot. I suppose that
Code (Note that the result will not display properly without the images referenced) I'm
Code is like this $.get( //'index.php?route=sale/order/infoforhome&token=<?php echo $token; ?>', 'index.php?route=common/home/orderinfo&token=<?php echo $token; ?>', {

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.