Archived

This topic is now archived and is closed to further replies.

MrPoopypants

JavaScript/dHTML question

Recommended Posts

MrPoopypants    124
I''m trying to get an image from the top left corner of the screen and move it to the bottom-right. i have tried doing:
		the_image.style.posLeft		+=	10; 
		the_image.style.posTop		+=	10; 
		the_image.style.position	+=	10; 
		the_image.style.marginLeft	+=	10;  
		the_image.style.marginTop	+=	10; 
 
and all of which either give me an error or do nothing at all any help would be great... Thanks

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You should check the CSS standard on w3c and the DOM reference for your browser of choice.

The most obvious thing you''re missing is that you need to set the style "position: absolute" to be able to move the element around on the page.

Share this post


Link to post
Share on other sites
MrPoopypants    124
ok great, thanks.

var cnt = 0;
var intNum;
var num1;
var num2;

function init() {
intNum = window.setInterval("moveImg()" , 100);
}

function moveImg(){
var rand = Math.random(Math.floor()) * 151;
var base = 101;
var num1 = Math.cos(rand * -1);
var num2 = Math.sin(rand * -1);
the_image.style.pixelLeft += num1;
the_image.style.pixelTop += num2;
base *= rand;
cnt++;

if (cnt == 200) { window.clearInterval(intNum); cnt = 0; }
}


This makes the image dance around the screen. Now if i want to make it go in an arc shaped pattern across the screen how could i come about doing that?

Share this post


Link to post
Share on other sites
Guest Anonymous Poster   
Guest Anonymous Poster
You''ll have to use a parabolic function. You can find this in any algebra book.

Share this post


Link to post
Share on other sites