PDA

View Full Version : help with centering text in scroller



Amiwan
05-25-2005, 11:10 PM
"pausing Up and Down Scroller"
http://www.dynamicdrive.com/dynamicindex2/crosstick.htm

I am trying to get the text in this scroller to align center instead of align left. I am new to java and am unable to see where I alter the code. Please help.

Thanks. Amiwna

jscheuer1
05-26-2005, 08:25 AM
Try this (red) in the style section of your page or if you have no style section create one in the head (red & blue):


<style type="text/css">
#first2 {
text-align:center;
}
#second2 {
text-align:center;
}
</style>

Amiwan
05-26-2005, 10:58 PM
Thank you for your assistance, however; that did not solve my problem. Everythign is still aligned left. Any other ideas?

Thanks
Amiwan

jscheuer1
05-27-2005, 03:37 AM
I was so sure it would work that I just now tested it here locally and it works fine here in both IE6 and FF1.0.4, what browser are you using? I am assuming one of those or one that will behave like one of those in this situation so, if that's the case:

.

Amiwan
06-01-2005, 12:48 AM
Well, I am obviously doing something wrong and would really appreciate the help. I haven't posted this site yet, so I have attached the html I am using. It is in an inline frame, however; that should not affect it should it? Again, I really appreciate the help. It doesn't seem like it should be this difficult, so I know that I am missing something. Thanks.



<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>PSW</title>

<style type="text/css">
#first2 {
text-align:center;
}
#second2 {
text-align:center;
}
</style>

</head>

<body>
<script type="text/javascript">

//configure the below five variables to change the style of the scroller
var scrollerdelay='3000' //delay between msg scrolls. 3000=3 seconds.
var scrollerwidth='100px'
var scrollerheight='100px'
var scrollerbgcolor='white'
//set below to '' if you don't wish to use a background image
var scrollerbackground=''

//configure the below variable to change the contents of the scroller
var messages=new Array()
messages[0]="<font face='Papyrus'><a>Jim Champion - Realtor</a></font>"
messages[1]="<font face='Papyrus'><a>Randy Selden - Realtor</a></font>"
messages[2]="<font face='Papyrus'><a>Schwartz Vacations</a></font>"
///////Do not edit pass this line///////////////////////

var ie=document.all
var dom=document.getElementById

if (messages.length>2)
i=2
else
i=0

function move(whichdiv){
tdiv=eval(whichdiv)
if (parseInt(tdiv.style.top)>0&&parseInt(tdiv.style.top)<=5){
tdiv.style.top=0+"px"
setTimeout("move(tdiv)",scrollerdelay)
setTimeout("move2(second2_obj)",scrollerdelay)
return
}
if (parseInt(tdiv.style.top)>=tdiv.offsetHeight*-1){
tdiv.style.top=parseInt(tdiv.style.top)-5+"px"
setTimeout("move(tdiv)",50)
}
else{
tdiv.style.top=parseInt(scrollerheight)+"px"
tdiv.innerHTML=messages[i]
if (i==messages.length-1)
i=0
else
i++
}
}

function move2(whichdiv){
tdiv2=eval(whichdiv)
if (parseInt(tdiv2.style.top)>0&&parseInt(tdiv2.style.top)<=5){
tdiv2.style.top=0+"px"
setTimeout("move2(tdiv2)",scrollerdelay)
setTimeout("move(first2_obj)",scrollerdelay)
return
}
if (parseInt(tdiv2.style.top)>=tdiv2.offsetHeight*-1){
tdiv2.style.top=parseInt(tdiv2.style.top)-5+"px"
setTimeout("move2(second2_obj)",50)
}
else{
tdiv2.style.top=parseInt(scrollerheight)+"px"
tdiv2.innerHTML=messages[i]
if (i==messages.length-1)
i=0
else
i++
}
}

function startscroll(){
first2_obj=ie? first2 : document.getElementById("first2")
second2_obj=ie? second2 : document.getElementById("second2")
move(first2_obj)
second2_obj.style.top=scrollerheight
second2_obj.style.visibility='visible'
}

if (ie||dom){
document.writeln('<div id="main2" style="position:relative;width:'+scrollerwidth+';height:'+scrollerheight+';overflow:hidden;background-color:'+scrollerbgcolor+' ;background-image:url('+scrollerbackground+')">')
document.writeln('<div style="position:absolute;width:'+scrollerwidth+';height:'+scrollerheight+';clip:rect(0 '+scrollerwidth+' '+scrollerheight+' 0);left:0px;top:0px">')
document.writeln('<div id="first2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:1px;">')
document.write(messages[0])
document.writeln('</div>')
document.writeln('<div id="second2" style="position:absolute;width:'+scrollerwidth+';left:0px;top:0px;visibility:hidden">')
document.write(messages[dyndetermine=(messages.length==1)? 0 : 1])
document.writeln('</div>')
document.writeln('</div>')
document.writeln('</div>')
}

if (window.addEventListener)
window.addEventListener("load", startscroll, false)
else if (window.attachEvent)
window.attachEvent("onload", startscroll)
else if (ie||dom)
window.onload=startscroll

</script>


<p align="center">&nbsp;</p>


</body>

</html>

jscheuer1
06-01-2005, 05:01 AM
I copied your code and the text was centered, I put it in an iframe, the text was centered. What html code and/or script and/or style are you using for your iframe?

Amiwan
06-08-2005, 09:39 PM
It did work. I did not use it correctly in my first attempt. I went back started from scratch and voila. It works. Thank you again. I appreciate all of the help.

Amiwan