Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,243 Programmers. There are 2,244 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

Image Visibility Toggle

 
Reply to this topicStart new topic

Image Visibility Toggle

dgallaher
post 6 May, 2008 - 12:59 PM
Post #1


New D.I.C Head

*
Joined: 6 May, 2008
Posts: 3



I want to make my animated (loading page) gif called 'load' visible while loading my image(s) as a background file in a table cell called 'mainSpace'. I started with this code:

CODE

document.getElementById('load').style.visibility = 'visible';
mainSpace.background="/clientimages/24231/home/images/ChurchSmallBG.jpg";
mainSpace.height=345;
document.getElementById('load').style.visibility = 'hidden';


The gif never shows up, and I tried leaving out the last line just to make sure the code was right, and sure enough it was.
I thought maybe the code that sets the background actually does not wait for the image to load, and that I needed to actually preload the image. So I tried this:

CODE

document.getElementById('load').style.visibility = 'visible';
imageAbout = new Image();
imageAbout.src = "/clientimages/24231/home/images/ChurchSmallBG.jpg";
mainSpace.background="/clientimages/24231/home/images/ChurchSmallBG.jpg";
mainSpace.height=345;
document.getElementById('load').style.visibility = 'hidden';



I still wasn't getting even a flicker on the gif, so I'm not sure what to do....

The gif is at the bottom of a left column cell. The loading image in the middle cell of the same table.

This isn't a huge deal except I am relying on a lot of background images of a sometimes fair size, and I have had enough of a lag in some of the loads that the animated loading-gif would be useful.

(I've also tried to set the background first as a simple image that says "loading..." and then set it to what I want, but this is not working either.)

Thanks,
David

website:
http://fbcmonahans.com/templates/System/de...&PID=571227

This post has been edited by dgallaher: 6 May, 2008 - 01:42 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


Martyr2
post 6 May, 2008 - 01:59 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 3,561

Well currently your pages are throwing errors saying that mainSpace is undefined. You must set that variable to the element you get from the document.getElementById() function call. This could be part of your problem.

smile.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

dgallaher
post 6 May, 2008 - 02:14 PM
Post #3


New D.I.C Head

*
Joined: 6 May, 2008
Posts: 3

I'm not getting those errors in IE7...?

I'm working on the site today, not sure if that's causing you interference?...

May I ask what browser you're using?

"You must set that variable to the element you get from the document.getElementById() function call."
I'm not sure what you mean by that. I've set the id of a table i'm using for scrollable images as "mainSpace". The loading-gif is supposed to show up at a different place, in a different cell, while the mainSpace table image is loading. By default its visibility is set to hidden. I know the code is working in some way, because I've tested the gif to stay visible, and it does.




User is offlineProfile CardPM
Go to the top of the page
+Quote Post

mocker
post 6 May, 2008 - 02:16 PM
Post #4


D.I.C Head

**
Joined: 14 Oct, 2007
Posts: 73

If javascript finds any errors, the rest of the code will break, so yea, set mainSpace to your element. If you use firefox, go to Tools->Error console and it will tell you exactly where your javascript is breaking


Edit:
to set mainSpace, add this before you use it
CODE

var mainSpace = document.getElementById('mainSpace');




This post has been edited by mocker: 6 May, 2008 - 02:19 PM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

dgallaher
post 7 May, 2008 - 08:45 AM
Post #5


New D.I.C Head

*
Joined: 6 May, 2008
Posts: 3

Ok, I made a variable for mainSpace, though IE for some reason does not seem to require it.
Still Firefox is not working...it seems to be loading an old version of the page, though i've restarted the computer...

Here's the core part of the code for each page, which defines a table (inside another table) with a scroll feature. What I'm aiming for is the center section to hold various images as the background of the table (with no foreground), and the table height resizing and scrolling if the image is long. I want the scrolling limited to that center section. It's been working fine in IE, but it would be nice to see it functional in Firefox.


CODE

            <td style="text-align: center" width="550" background="/clientimages/24231/home/images/HomeBG.jpg">&nbsp;
            <div style="overflow: auto; width: 550px; height: 365px">
            <table id="mainSpace" height="100" cellspacing="0" cellpadding="0" width="490" align="center" background="" border="0">
                <tbody>
                    <tr>
                        <td valign="middle" align="center"><script>
var mainSpaceP = document.getElementById('mainSpace');
mainSpaceP.background="/clientimages/24231/children/images/cover.jpg";
mainSpaceP.height=345;
</script></td>
                    </tr>
                </tbody>
            </table>



Are there any obvious problems with this code?



This post has been edited by dgallaher: 7 May, 2008 - 09:39 AM
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 08:25AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month