xiaoxiangz
asked on
java script scroll text
Hi,
I am writing a javascript text scroller. It use
css clip property to create a viewpoint on a moving
layer. The code works well under IE. But has some
issues in NS 4.7. What happened is , the first message
show up, and scrolled. But the second message never show
up. I only know it has something to do with
the statement div.clip.top = cliptop;
if I set div.clip.top=0, the second message will show up.
But of course, the effect is not what I want.
Can somebody help me out.
Thanks a lot. I am giving out all my points.
Sean
//html file
<html>
<head>
<script src=scroll.js>
</script>
</head>
<body onLoad="startTextScroll(); ">
<div id="msg" style="position:absolute;l eft:100;to p:200; width:150; height:150; z-index: 0; visibility: visible; overflow: hidden;">
<script>
document.write(messages[0] );
</script>
</div>
</body>
</html>
//scroll.js
var isNS = (navigator.appName == "Netscape" && parseInt(navigator.appVers ion) >= 4);
var viewpointtop;
var scrollerwidth;
var scrollerheight;
var clipbottom;
var cliptop;
var pause=1000;
var speed=100;
var messages=new Array()
messages[0]='<p> Scrolling Layers</p><p> It is written by Shane Zhang.</P><P>Jun 6, 2002 </P>';
messages[1]='<p>This code uses css clip </p><p>property to create a fix</p><p> viewpoint on a moving layer .</p>';
messages[2]='<p>3. Hope it be of some use to you.</p> Bye bye.';
//the message to showed
i=0;
function setClipWindow (div)
{
if(isNS)
{
div.clip.top = cliptop;
div.clip.bottom = clipbottom ;
div.clip.left = 0 ;
div.clip.right = scrollerwidth ;
}else{
newrect="rect("+cliptop+", "+scroller width+","+ clipbottom +","+"0)";
div.clip=newrect;
}
}
function moveMsg(div)
{
if (isNS) x=div.top;
else x=div.pixelTop;
if (x>=viewpointtop-scrollerh eight)
{
// this is the moving part
if (x>=viewpointtop)
{
//moving in
cliptop=0;
clipbottom+=5;
}
else
{
//moving out
cliptop+=5;
}
if(isNS) div.top-=5;
else div.pixelTop-=5;
setClipWindow(div);
//all mesg show up, pause a while
if(cliptop==5)
{
cliptop=0;
setClipWindow(div);
setTimeout("moveMsg(div)", pause);
cliptop=10;
}
else
setTimeout("moveMsg(div)", speed);
}
else
{
//new message
if (i==messages.length-1)
i=0;
else
i++;
if(isNS)
{
document.msg.document.open ();
document.msg.document.writ e(messages [i]);
document.msg.document.clos e();
}
else {
document.all["msg"].innerH TML=messag es[i];
}
cliptop=0;
clipbottom=5;
if(isNS)
div.top=viewpointtop+scrol lerheight;
else
div.pixelTop=viewpointtop+ scrollerhe ight;
setClipWindow(div);
setTimeout("moveMsg(div)", speed);
}
}
function getObjectByName(name) {
return (isNS) ? eval('document.'+name) : eval('document.all.'+name+ '.style');
}
function startTextScroll(){
div=getObjectByName("msg") ;
if(isNS) viewpointtop=div.top;
else viewpointtop=div.pixelTop;
scrollerwidth=150;
scrollerheight=150;
//at the begining show the whole message
cliptop=0;
clipbottom=scrollerheight;
moveMsg(div);
}
I am writing a javascript text scroller. It use
css clip property to create a viewpoint on a moving
layer. The code works well under IE. But has some
issues in NS 4.7. What happened is , the first message
show up, and scrolled. But the second message never show
up. I only know it has something to do with
the statement div.clip.top = cliptop;
if I set div.clip.top=0, the second message will show up.
But of course, the effect is not what I want.
Can somebody help me out.
Thanks a lot. I am giving out all my points.
Sean
//html file
<html>
<head>
<script src=scroll.js>
</script>
</head>
<body onLoad="startTextScroll();
<div id="msg" style="position:absolute;l
<script>
document.write(messages[0]
</script>
</div>
</body>
</html>
//scroll.js
var isNS = (navigator.appName == "Netscape" && parseInt(navigator.appVers
var viewpointtop;
var scrollerwidth;
var scrollerheight;
var clipbottom;
var cliptop;
var pause=1000;
var speed=100;
var messages=new Array()
messages[0]='<p> Scrolling Layers</p><p> It is written by Shane Zhang.</P><P>Jun 6, 2002 </P>';
messages[1]='<p>This code uses css clip </p><p>property to create a fix</p><p> viewpoint on a moving layer .</p>';
messages[2]='<p>3. Hope it be of some use to you.</p> Bye bye.';
//the message to showed
i=0;
function setClipWindow (div)
{
if(isNS)
{
div.clip.top = cliptop;
div.clip.bottom = clipbottom ;
div.clip.left = 0 ;
div.clip.right = scrollerwidth ;
}else{
newrect="rect("+cliptop+",
div.clip=newrect;
}
}
function moveMsg(div)
{
if (isNS) x=div.top;
else x=div.pixelTop;
if (x>=viewpointtop-scrollerh
{
// this is the moving part
if (x>=viewpointtop)
{
//moving in
cliptop=0;
clipbottom+=5;
}
else
{
//moving out
cliptop+=5;
}
if(isNS) div.top-=5;
else div.pixelTop-=5;
setClipWindow(div);
//all mesg show up, pause a while
if(cliptop==5)
{
cliptop=0;
setClipWindow(div);
setTimeout("moveMsg(div)",
cliptop=10;
}
else
setTimeout("moveMsg(div)",
}
else
{
//new message
if (i==messages.length-1)
i=0;
else
i++;
if(isNS)
{
document.msg.document.open
document.msg.document.writ
document.msg.document.clos
}
else {
document.all["msg"].innerH
}
cliptop=0;
clipbottom=5;
if(isNS)
div.top=viewpointtop+scrol
else
div.pixelTop=viewpointtop+
setClipWindow(div);
setTimeout("moveMsg(div)",
}
}
function getObjectByName(name) {
return (isNS) ? eval('document.'+name) : eval('document.all.'+name+
}
function startTextScroll(){
div=getObjectByName("msg")
if(isNS) viewpointtop=div.top;
else viewpointtop=div.pixelTop;
scrollerwidth=150;
scrollerheight=150;
//at the begining show the whole message
cliptop=0;
clipbottom=scrollerheight;
moveMsg(div);
}
ASKER
The strange thing is
if I do this the code will work under NS 4.7
if(cliptop==0) cliptop=-1;
div.clip.top=cliptop;
if I do this the code will work under NS 4.7
if(cliptop==0) cliptop=-1;
div.clip.top=cliptop;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
points to knightEknight
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
ahosang
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
points to knightEknight
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
ahosang
EE Cleanup Volunteer
Finalized as proposed
modulo
Community Support Moderator
Experts Exchange
modulo
Community Support Moderator
Experts Exchange
try this:
div.clip.top = cliptop||0;