Click here to Skip to main content
15,885,914 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Java Script moveing a picture around the screen Pin
Boaz Yaari27-May-12 10:43
Boaz Yaari27-May-12 10:43 
GeneralRe: Java Script moveing a picture around the screen Pin
BobJanova28-May-12 23:34
BobJanova28-May-12 23:34 
GeneralRe: Java Script moveing a picture around the screen Pin
Boaz Yaari27-May-12 11:22
Boaz 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
professionalAli 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
professionalAli Al Omairi(Abu AlHassan)31-May-12 7:40 
GeneralRe: Java Script moveing a picture around the screen Pin
enhzflep31-May-12 10:38
enhzflep31-May-12 10:38 
GeneralRe: Java Script moveing a picture around the screen Pin
Ali Al Omairi(Abu AlHassan)1-Jun-12 1:15
professionalAli Al Omairi(Abu AlHassan)1-Jun-12 1:15 
AnswerRe: Java Script moveing a picture around the screen Pin
enhzflep29-May-12 10:41
enhzflep29-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!

JavaScript
<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
professionalTesic 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
professionalAli 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
OrangeV24-May-12 5:40 
AnswerRe: A Unique Problem - Ignoring Placing Page on Back Button History Pin
Sandeep Mewara24-May-12 9:02
mveSandeep Mewara24-May-12 9:02 
QuestionHow to make the text box draggable using jQuery? Pin
Tesic Goran23-May-12 8:45
professionalTesic Goran23-May-12 8:45 
AnswerRe: How to make the text box draggable using jQuery? Pin
Vitaly Tomilov24-May-12 16:13
Vitaly Tomilov24-May-12 16:13 
AnswerRe: How to make the text box draggable using jQuery? Pin
ZurdoDev25-May-12 8:47
professionalZurdoDev25-May-12 8:47 
Questionfinding a substring match at the beginng of a of another string. Pin
Steve Holdorf22-May-12 7:16
Steve 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
Vitaly Tomilov22-May-12 8:51 
AnswerRe: finding a substring match at the beginng of a of another string. Pin
scottgp22-May-12 9:25
professionalscottgp22-May-12 9:25 
QuestionSimple autocomplete textbox control problem Pin
Steve Holdorf20-May-12 11:10
Steve Holdorf20-May-12 11:10 
AnswerRe: Simple autocomplete textbox control problem Pin
Vitaly Tomilov20-May-12 11:27
Vitaly Tomilov20-May-12 11:27 
QuestionHow to read Doc or Pdf file using javascript or jquery Pin
priya014319-May-12 2:03
priya014319-May-12 2:03 
AnswerRe: How to read Doc or Pdf file using javascript or jquery Pin
frostcox19-May-12 21:24
frostcox19-May-12 21:24 
QuestionJquery quering the db Pin
frostcox18-May-12 8:20
frostcox18-May-12 8:20 
AnswerRe: Jquery quering the db Pin
Vitaly Tomilov20-May-12 11:31
Vitaly Tomilov20-May-12 11:31 
GeneralRe: Jquery quering the db Pin
frostcox21-May-12 6:00
frostcox21-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.