Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

simple horizontal scroll 1

Status
Not open for further replies.

derwent

Programmer
May 5, 2004
428
GB
I have an animated gif of a person walking. I would like a simple script to make him move from one side of the screen to the other.

All of the scripts I have found are massive designed to display multiple news stories, does anyone know of a basic one that will make my man move across the screen then when he gets to the end, do it again??

Thanks
 

Here's a simple example. Let me know if it's what you want.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<script language='JavaScript'>
<!--

function moveManAcrossScreen() {
    var man = document.getElementById('the_man');
	var max = document.body.offsetWidth;
	var step = 5;
    var cur = parseInt(man.style.left);

	if (cur < max)
	    man.style.left = parseInt(man.style.left) + step + "px";
	else
		man.style.left = "0px";
	//alert(man.style.left);
	setTimeout("moveManAcrossScreen()", 50);
}

-->
</script>
</HEAD>

<BODY onload="moveManAcrossScreen();">
<div id="the_man" style="left: 0px; position: absolute;">
man<br>
</div>
</BODY>
</HTML>

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
That is great thanks.

Is there any way to remove the horizontal scrollbar that appears on the browser when it gets to the edge?

Is there a good site where I can learn javascript like that, now it`s there it looks quite simple but I wouldn`t have had a clue where to start!!
 
What I would do to remove the scrollbar is to just have it not display in the first place. The reason it's displaying is because I set the max equal to the available width of the window. What you could do is set the max to the available width of the window MINUS the width of the image. If your image was 100 pixels in width, you could do this:

[tt]var max = document.body.offsetWidth[red] - 100[/red];[/tt]

As for a site, when I'm unsure about something I usually just Google. The site is amazing, I just basically type in something like "javascript move image horizontal" or something.

Another great source is this very site. I've already learned a lot here just helping people.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top