473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Centering text screws up Javascript effect

BT
I have taken over the support of an existing webpage and I need to revise
the page so that it is centered (left and right) on the screen instead of
aligned on the left. I can do this easily, but there is a little JavaScript
that doesn't work correctly after I center it.

I have tried to realign the page with either <centertag or align="left"
attribute, but the pictures displayed with the JavaScript get messed up with
everything I've tried. Also, the JavaScript doesn't seem to work at all
when I view the page with Firefox 1.0.6.

It's relatively simple page; could someone offer a suggestion for centering
the text and keeping the pictures displayed correctly? Any idea why it
doesn't display the pictures right in Firefox?

thanks, the page is www.crhschoir.org
Nov 10 '06 #1
3 3646
On 2006-11-10, BT <no@xnono.comwrote:
I have taken over the support of an existing webpage and I need to revise
the page so that it is centered (left and right) on the screen instead of
aligned on the left. I can do this easily, but there is a little JavaScript
that doesn't work correctly after I center it.
I tried setting align="center" on the two top-level tables
(alternatively set style="margin: 0 auto" on them), and it seemed to
work OK in Firefox. What's the JavaScript problem?
I have tried to realign the page with either <centertag or align="left"
attribute, but the pictures displayed with the JavaScript get messed up with
everything I've tried. Also, the JavaScript doesn't seem to work at all
when I view the page with Firefox 1.0.6.
Looks like the problem is with the values you're assigning to
imgs.style.opacity, which should be a number between 0 and 1 not a
percentage.

Change

imgs.style.MozOpacity = 0 + '%';
imgs.style.MozOpacity = opacity + '%';

to

imgs.style.MozOpacity = 0;
imgs.style.MozOpacity = opacity / 100.0;
Nov 10 '06 #2
BT
Thanks for the assistance. I'm sure it is hard to see the problem without a
full page of images, etc to see. I went ahead and made the changes to align
the two top level tables so you could see them and posted the page as:

www.crhschoir.org/index-center.html

Here you can see that the set of fading images is not centered and it
partially overlies a static copy of one of the images that IS centered. The
code includes the fading images affected by the script as div id="img1"
and div id="img2" , but the static image is listed in the next line of
html. When it is on the left side of the page, the images overlay and you
never see the static one. I'm guessing this was set up for displaying the
static image to people who have javascript turned off. Still, it looks like
the javascript fading images are not centered and I still can't figure out
why.

Also, the fix for Firefox does get the images to fade in/out, but after a
complete cycle the two images flash back and forth 8 times in about 2
seconds. It doesn't flash like this in IE6.

Does the new posted file give you any more ideas?

thanks, BDT
"Ben C" <sp******@spam.eggswrote in message
news:sl*********************@bowser.marioworld...
On 2006-11-10, BT <no@xnono.comwrote:
>I have taken over the support of an existing webpage and I need to revise
the page so that it is centered (left and right) on the screen instead of
aligned on the left. I can do this easily, but there is a little
JavaScript
that doesn't work correctly after I center it.

I tried setting align="center" on the two top-level tables
(alternatively set style="margin: 0 auto" on them), and it seemed to
work OK in Firefox. What's the JavaScript problem?
>I have tried to realign the page with either <centertag or align="left"
attribute, but the pictures displayed with the JavaScript get messed up
with
everything I've tried. Also, the JavaScript doesn't seem to work at all
when I view the page with Firefox 1.0.6.

Looks like the problem is with the values you're assigning to
imgs.style.opacity, which should be a number between 0 and 1 not a
percentage.

Change

imgs.style.MozOpacity = 0 + '%';
imgs.style.MozOpacity = opacity + '%';

to

imgs.style.MozOpacity = 0;
imgs.style.MozOpacity = opacity / 100.0;

Nov 10 '06 #3
On 2006-11-10, BT <no@xnono.comwrote:
Thanks for the assistance. I'm sure it is hard to see the problem without a
full page of images, etc to see. I went ahead and made the changes to align
the two top level tables so you could see them and posted the page as:

www.crhschoir.org/index-center.html

Here you can see that the set of fading images is not centered and it
partially overlies a static copy of one of the images that IS centered. The
code includes the fading images affected by the script as div id="img1"
and div id="img2" , but the static image is listed in the next line of
html. When it is on the left side of the page, the images overlay and you
never see the static one. I'm guessing this was set up for displaying the
static image to people who have javascript turned off. Still, it looks like
the javascript fading images are not centered and I still can't figure out
why.
I see, I probably would have noticed that was the problem if I'd been
paying more attention.

Anyway, it's happening because #img1 and #img2 are absolutely positioned
at 198px left of their container (the body probably, something outside
the table anyway). So they stay put even when the table is centered.

The fix is to change

#img1 {position:absolute; width:572px; height:100px; left:198px; top:100px; z-index:1; visibility:hidden;}
#img2 {position:absolute; width:572px; height:100px; left:198px; top:100px; z-index:2}

to

#img1 {position:absolute; width:572px; height:100px; z-index:1; visibility:hidden;}
#img2 {position:absolute; width:572px; height:100px; z-index:2}

i.e. get rid of left and top. Then the images just get their "static"
position, which is inside the table cell where they belong.

If this proves unreliable in some browsers-- it works in FF, but I
haven't tried anything else-- which it may do as according to the spec
the UA is free to "guess" the static position for unspecified absolutely
positioned elements, make them both top: 0; left: 0 and wrap them in a
relatively positioned div where they appear in the table. i.e.:

<td width="572">
<div style="position: relative" <---- insert "wrapper" div
<div id="img1"...>

This way the relatively positioned div provides a container for the
absolutely positioned #img1 and #img2 to be positioned 0 from the top
and 0 from the left of, and itself sits in the table cell in the normal
way.
Also, the fix for Firefox does get the images to fade in/out, but after a
complete cycle the two images flash back and forth 8 times in about 2
seconds. It doesn't flash like this in IE6.
I'm not seeing that, the two images seem to interchange at a consistent
speed.

I do think it's nicer style though to take the call to setTimeout out of
FadeImg and replace it with a call to setInterval outside FadeImg.

i.e.

function main()
{
setInterval("FadeImg()", speed);
}
onload = main;

Don't know if it will make any difference.

This will mean editing below where it says reassuringly "You don't have
to edit below this line".
Nov 10 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Jeff Thies | last post by:
I have a series of blocks that are float left that I need centered on the page. <div class="center" align="center"> <div style="width: 100 px;float: left">thumbnail 1</div> <div style="width:...
19
by: George Ziniewicz | last post by:
.. I try to use CSS when possible, though I am still learning and don't maximize its use. In particular, I still use a table to provide for a centered image in a few slideshows (though table...
7
by: Erik Schulp | last post by:
Hi all, I am trying to get a CSS defined layout to center on the page, have tried doing this with the <center></center> tags but than everything is centered, including text etc etc. What...
5
by: Robert J. O'Hara | last post by:
For some time I've made use of the max-width property in CSS to cause my pages to appear as a centered block against a contrasting background. This works well in new browsers (Mozilla, etc.) and...
15
by: red | last post by:
How do I center two side by side divs ? I've been writing css pages for a while but there's one thing tha still eludes me. I can center a div with margin auto. I can place two divs side by side...
3
by: yawnmoth | last post by:
I'm trying to center list elements in a webpage I'm working on, and setting margin-left to auto for ol (or ul) seems to prevent the number (or bullet) from displaying in IE6 (strict mode) and...
3
by: John Pote | last post by:
1. Horizontal centering a <divin browser window. The current trend seems to be to place page content in a fixed width area in the middle of the browser window. How is this achieved? If I use a...
3
by: rsteph | last post by:
I'm using two divs to create a shadowed-box type effect. Within the top div I want to put an image. I can get the image to center right to left, but not top to bottom. I'm making a series of boxes,...
9
by: Neal | last post by:
http://www.brassattackofspringfield.com/gigs.html CSS at http://www.brassattackofspringfield.com/default.css Opera and IE render caption as desired. Firefox does not. Why? And is there a fix?
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.