Click here to Skip to main content
12,445,004 members (53,366 online)

JavaScript

 
GeneralRe: Java Script moveing a picture around the screen Pin
Boaz Yaari27-May-12 10:43
memberBoaz Yaari27-May-12 10:43 
GeneralRe: Java Script moveing a picture around the screen Pin
BobJanova28-May-12 23:34
memberBobJanova28-May-12 23:34 
GeneralRe: Java Script moveing a picture around the screen Pin
Boaz Yaari27-May-12 11:22
memberBoaz Yaari27-May-12 11:22 
GeneralRe: Java Script moveing a picture around the screen Pin
Ali Al Omairi(Abu AlHassan)28-May-12 0:38
memberAli Al Omairi(Abu AlHassan)28-May-12 0:38 
AnswerRe: Java Script moveing a picture around the screen Pin
Ali Al Omairi(Abu AlHassan)31-May-12 7:40
memberAli Al Omairi(Abu AlHassan)31-May-12 7:40 
GeneralRe: Java Script moveing a picture around the screen Pin
enhzflep31-May-12 10:38
memberenhzflep31-May-12 10:38 
GeneralRe: Java Script moveing a picture around the screen Pin
Ali Al Omairi(Abu AlHassan)1-Jun-12 1:15
memberAli Al Omairi(Abu AlHassan)1-Jun-12 1:15 
AnswerRe: Java Script moveing a picture around the screen Pin
enhzflep29-May-12 10:41
memberenhzflep29-May-12 10:41 
Hi there.
It seems that there's a couple of problems with your code.

Firstly, it bogs down quickly due to the way that the init function is set to create a new timer each time it's called

Next, elem.setAttribute("style" ..... - this sets the style for the element - the style is defined inline, that is - a single string that contains all of the style info - just like the style string you have for the ss div

I think there was something else, though it's been a really long day.

Anyway, here's some code that works - even if it is a bit epileptic!

<html>
	<head>
		<title>JavaScript: Moving an Image</title>
		<script type="text/javascript">
			function Init()
			{
					setInterval("onMove();",100);
			}
 
			function constructStyleString(xPos, yPos)
			{
				var result = "margin-top: " + yPos + "px;";
				result += "margin-left: " + xPos + "px;";
				return result;
			}
			 
			function onMove()
			{
				var xPos, yPos;
				xPos = Math.random() * 50;
				yPos = Math.random() * 20;
				var elem = document.getElementById("imgContainer");
				elem.setAttribute("style", constructStyleString(xPos, yPos));
			}
		</script>
	</head>
	<body onload="Init();">
		<div  id="imgContainer" style="height: 200px; width: 500px;">
			<img class="image" id="img1" src="img/progBar1024-2.gif" height="24px" width="10px"/>
		</div>
	</body>
</html>

QuestionHow to change mouse cursor in jQuery UI resizable plugin? Pin
Tesic Goran25-May-12 0:06
memberTesic Goran25-May-12 0:06 
AnswerRe: How to change mouse cursor in jQuery UI resizable plugin? Pin
Ali Al Omairi(Abu AlHassan)29-May-12 5:08
memberAli Al Omairi(Abu AlHassan)29-May-12 5:08 
QuestionA Unique Problem - Ignoring Placing Page on Back Button History Pin
OrangeV24-May-12 5:40
memberOrangeV24-May-12 5:40 
AnswerRe: A Unique Problem - Ignoring Placing Page on Back Button History Pin
Sandeep Mewara24-May-12 9:02
mvpSandeep Mewara24-May-12 9:02 
QuestionHow to make the text box draggable using jQuery? Pin
Tesic Goran23-May-12 8:45
memberTesic Goran23-May-12 8:45 
AnswerRe: How to make the text box draggable using jQuery? Pin
Vitaly Tomilov24-May-12 16:13
memberVitaly Tomilov24-May-12 16:13 
AnswerRe: How to make the text box draggable using jQuery? Pin
ryanb3125-May-12 8:47
memberryanb3125-May-12 8:47 
Questionfinding a substring match at the beginng of a of another string. Pin
Steve Holdorf22-May-12 7:16
memberSteve Holdorf22-May-12 7:16 
AnswerRe: finding a substring match at the beginng of a of another string. Pin
Vitaly Tomilov22-May-12 8:51
memberVitaly Tomilov22-May-12 8:51 
AnswerRe: finding a substring match at the beginng of a of another string. Pin
scottgp22-May-12 9:25
memberscottgp22-May-12 9:25 
QuestionSimple autocomplete textbox control problem Pin
Steve Holdorf20-May-12 11:10
memberSteve Holdorf20-May-12 11:10 
AnswerRe: Simple autocomplete textbox control problem Pin
Vitaly Tomilov20-May-12 11:27
memberVitaly Tomilov20-May-12 11:27 
QuestionHow to read Doc or Pdf file using javascript or jquery Pin
priya014319-May-12 2:03
memberpriya014319-May-12 2:03 
AnswerRe: How to read Doc or Pdf file using javascript or jquery Pin
Mickt198519-May-12 21:24
memberMickt198519-May-12 21:24 
QuestionJquery quering the db Pin
Mickt198518-May-12 8:20
memberMickt198518-May-12 8:20 
AnswerRe: Jquery quering the db Pin
Vitaly Tomilov20-May-12 11:31
memberVitaly Tomilov20-May-12 11:31 
GeneralRe: Jquery quering the db Pin
Mickt198521-May-12 6:00
memberMickt198521-May-12 6:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Mobile
Web01 | 2.8.160811.3 | Last Updated 24 Aug 2016
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid