Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-24-2010, 09:39 PM   PM User | #1
homeLearning
New to the CF scene

 
Join Date: Jun 2010
Location: montreal
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
homeLearning is an unknown quantity at this point
Very simple js Scrolling window code not working?

Can someone please help with this code.
The window is supposed to automatically scroll and move but it isn't working.
(It was taken from a discontinued book called javascript in 24hrs)
The javascript:


Quote:
var pos=100;

function Scroll(){

if (!document.getElementById ) return;
obj=document.getElementById("thetext");
pos -=1;
if(pos < 0-obj.offsetHeight + 130) return;
obj.style.top=pos;
window.setTimeout("Scroll();", 30);

}

//start scrolling when the page loads
window.onload=Scroll;
the css:

Quote:
#thewindow{
position:relative;
width:180px;
height:150px;
overflow:hidden;
border:2px solid red;

}

#thetext{
position:absolute;
width:170px;
left:5px;
top:100px;
}
the html:
Quote:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link rel="stylesheet" type="text/css" href="scroll.css" />
</head>

<body>

<h1> scrolling window example</h1>
<p>This example shows a scrolling window created using javascript and the w3cdom.The red border window is actually a layer that shows a cliped portion of a larger layer"</p>
<div id="thewindow">
<div id="thetext">

<p>This is the first paragraph of the scrolling message.The message is created with regular html</p>
<p>Entries within the scrolling area can use any html tags.They can contain <a href="#">links</a></p>
<p> No limit to the number of paragraphs that you can include here...</p>
<ul>
<li>For example you could format items using a bulleted list.</li>
</ul>

<p>The scrolling ends when the last part of tht scrolling text ids on the screen.You've reached the end.</p>

</div>
</div>

</body>
</html>
homeLearning is offline   Reply With Quote
Old 07-25-2010, 01:35 AM   PM User | #2
RandomUser531
New Coder

 
Join Date: Jul 2010
Posts: 61
Thanks: 0
Thanked 21 Times in 21 Posts
RandomUser531 is on a distinguished road
First try amending the relevant line as shown.
Code:
obj.style.top = pos +'px';
RandomUser531 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:04 PM.


Advertisement
Log in to turn off these ads.