473,461 Members | 1,791 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to paint an element in screen using javascript?

12 Nibble
Expand|Select|Wrap|Line Numbers
  1. <div class="body">
  2.     <div id="board">
  3.       <div id="bat" class="bat"></div>
  4.       <div id="ball" class="ball"></div>
  5.     </div>
  6.   </div>
  7.  
This is my HTML.
I've done CSS For all of them and generated this:

Now, I want the bat to move left and right when I press arrow keys.
Expand|Select|Wrap|Line Numbers
  1. window.addEventListener("keydown", function (e) {
  2.  
  3.   switch (e.key) {
  4.     case "ArrowLeft":
  5.       batDir.x = -1;
  6.       batDir.y = 0;
  7.       paintBat(batDir.x, batDir.y);
  8.       break;
  9.     case "ArrowRight":
  10.       batDir.x = 1;
  11.       batDir.y = 0;
  12.       paintBat(batDir.x, batDir.y);
  13.       break;
  14.  
  15.   }
  16. })
  17.  
  18.  
My goal is to paint the bat at new position. I'm wondering how to do it.

The logic should be

newBatPosition.x=oldBatPosition.x+batDirection.x
newBatPosition.y=oldBatPosition.y+batDirection.y

But what will do the job of painting newBatPosition.x and newBatPosition.y is what I'm not clear of. I'm not using canvas.

Plus, what'll be the oldBatPosition? I've used CSS to paint them. So, I'm wondering how do I get oldBatPosition coordinates as well.
Jan 11 '23 #1
0 1588

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: NewbieJon | last post by:
I am attempting to send the variable "sComputerName" from my ActiveX script to "GetInfo.asp" using javascript. (Having been advised this is the way to get my ActiveX variable into my ASP script) ...
9
by: CW | last post by:
I wrote an HTML based chat application. The front end is built entirely on HTML + javascript. Essentially, I have a hidden frame that's refreshed frequently and any new messages are displayed in...
1
by: keerthana_m_2003 | last post by:
Hello: I am designing a web page where there are some buttons text etc. I want to design it in such a way that, irrespective of the screen size, resolutoin; the buttons will have to come always...
6
by: Vikram | last post by:
I have added some input elements on a page using javascript at client side. when i submit the page, i am unable to access the values of input elements created using request.form. Are elements...
1
by: c.verma | last post by:
I am not able to hide a href element using javascript. Here is my code written on aspx page. On the click of "OK" button, I want to hide href element. But I am getting message: Object required....
1
by: =?Utf-8?B?amVmZjMwNDg=?= | last post by:
Hi, I want to incorporate a JavaScript routine (found on the internet) in my page that will restore the scrollbar position of a div tag on postback. I am using master pages which complicates...
5
by: nesha | last post by:
Hi, I have a html page in which im using a form. In that form i placed a div element within the form. That div element has another div element within that. how to get the innermost div element value...
1
by: vivek kapile | last post by:
Title:Dynamically adding table row with a checkbox using JavaScript Author:Vivek Kapile Email:snipped Language:JavaScript Platform:JavaScript in ASP.net Technology:Used in ASP.net...
1
by: harsh gidra | last post by:
I am trying to POST dynamic form elements added using javascript but unable to do so. The elements are being shown when I add them but don't see anything on the test.php page. I have been trying...
1
by: ahmednawazbutt | last post by:
I have an .htm page wwhich consits of a frame with 0 border,width and height Now, when I enter a key,i.e onkeyup (keyboard pressing)event occurs, the form is submitted to asp.net page, which...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.