Forum Moderators: open

Message Too Old, No Replies

Gif animation and javascript conflict

After invoking the javascript an animation in the same file is not working

         

Rajiv

3:05 pm on May 15, 2004 (gmt 0)

10+ Year Member



Hi..

I am using an javascript to change the images on a HTML Page. I have an button which says "Next Image" and when clicked on it, a new image appears on the same HTML Page and so on upto 5 images. This is done using a javascript.

Also, I've a gif animation which is independent of the above said javascript which is on the same HTML page.

However, when I click on the "Next Image" the gif animation is stopped.

Please help!

With warm regards
Rajiv

korkus2000

4:19 pm on May 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



When you are calling the JS you are effectively stopping the page. When you call the function return false to kick it back off again.

onclick="changeImages();return false;"

Rajiv

5:40 pm on May 15, 2004 (gmt 0)

10+ Year Member



Thank you korkus2000.. It worked!

With warm regards
Rajiv

AaronAgassi

1:21 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



I am experiencing a similar vexation: My animated gifs tend to stop animating while certain JavaScripts run. What to do?

Bernard Marx

1:40 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's an interesting one, Korkus.
Can you expand on it for us, or give is any links/pointers?

korkus2000

7:32 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I had this problem a long time ago. I wanted to do calculations in a text box. Clicking the button or link created an event in the browser that effectively expected a new page to be loaded. It is kind of like a bug. With JavaScript you are hijacking the normal actions of the page elements and confusing the browser. The browser expects to go to a new page when you click a link. You have to return false to tell the browser you didn't really mean to click the link.

I don't really have any links. I think something about it is burried in netscape's dev center. It is by design that it works this way, but like I siad it acts like a bug.

AaronAgassi

8:20 pm on Jun 28, 2004 (gmt 0)

10+ Year Member



I'm running that bubbles special effects script, and it's not only stalling the gif animation, but even the slideshow cross fade script in an iframe. What to do?

Bernard Marx

10:16 pm on Jun 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I see. I haven't messed with animated gifs for a while, and don't usually put script in links either. I do it here as it's common here, and it does combine style with function in one attribute. I take it that this is restricted to Netscape. It sort of makes sense - Why should the page continue to animate while you are running out of the back door?

AaronAgassi,

By 'stalling' do you mean 'slowing down'? If that's the case, then it's because you are punishing the cpu with DHTML effects & animation (same might be said for you visitors too).

If the gif stops dead, then it still may not be related to the above problem (does it happen in IE too?). Your 'bubbles' effect is probably not started by a user clicking on a link.
Is it?

What to do?

If it is related to the current thingy, then you need to return false from whatever function is being called by the link. It maybe looks something like this:

function troubleWithBubbles()
{
..some code..
setInterval(...code...,delay) // or setTimeout
return false // <-- add this bit
}

AaronAgassi

3:10 am on Jun 29, 2004 (gmt 0)

10+ Year Member



By stalling, I mean, for the most part, that the gifs simply stop animating. But I used the word 'stalling,' because on one of the pages I actually managed to get the gif animations work again, if a bit sluggishly, simply by moving the background wav calls to an iframe within an iframe. It's as though I where getting positive results by somehow introducing a disruption.

But alas, this modification does not seem to work with the other pages using the same or similar scripts and manifesting the same problem. However, I notice that sometimes I can get the gifs to advance by minimizing and the restoring the browser. But how far they advance seems to depend upon how long I wait before restoring the browser. Indeed, they seem to be animating, unseen, but fail to refresh so as to actually become visible within the browser, IE, which I keep up to date...

And no, this issue is not a function of clicking a link, although I have seen that as well on another of my pages, where it produces an interesting artifact.

Bernard Marx

10:19 am on Jun 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think I have anything to offer on your animation problem, "artefacts" perhaps.
I find these disappear if the image either:

a) is contained in a closely wrapping block container [div, cell etc].
b) has a border (!=0).

If there's only a single background color to take care of on the page. I'll set:

body:{background-color: _aColour_;}
img{border: solid 1px _aColor_;}

AaronAgassi

11:13 am on Jun 29, 2004 (gmt 0)

10+ Year Member



The animated gifs in question are already absolutely positioned, hence div contained, and img border="0" On some pages there is a black background while on others there are background images, most static, but on one other a tiled animated gif animation. However, I'm having trouble setting the image border colors (which, of course, will not be seen once their width is again reset back to zero).

The borders, when given any positive width, appear blue because the images are linked to other pages or else, otherwise, will appear black. Can I have an example statement of an image with it's own unique border color? (Again, the problem is already manifest without any images being clicked, and become moot once they are because a different page is opened.)

Bernard Marx

4:51 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



..hence div contained,

The div may need to be exactly the same dims as the image.
The image may need explicitly declared dims (perhaps in tag attributes)

Can I have an example statement of an image with it's own unique border color?

#imageID{border:solid 1px #ffffff;}

The borders, when given any positive width, appear blue because the images are linked to other pages

You will need to override the default link style / hover behaviour.

<a href="blah.htm" class="imglink"><img src="blah.jpg" width = ...></a>

...css...

a.imglink:link,
a.imglink:visited,
a.imglink:hover
{
border:solid 1px #ffffff;
}

AaronAgassi

6:33 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



I'm now beginning to feel distinctly out of my depth. I'm looking for discrete items to modify or tweak, but I see here a host of to me unfamiliar assumptions. For example, I'm not using CSS or class, that you seem to assume. I'm not even using image ID. You seem to assume that the gifs are called by the script in question, where as I simply added them into the html page that also includes the script.

Bernard Marx

7:18 pm on Jun 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry about that. I won't say "perhaps you should use CSS", but if you want to venture into it, those examples will work. Adding an id to an image is as easy as....

I can't think of a way to override link border styles with inline CSS. So no borders, but wrapped in divs seems the option. Back to this:

Can I have an example statement of an image with it's own unique border color?

<img src="etc" style="border:solid 1px red">

Still CSS, but inline. There's probably an HTML attribute option too.

assume that the gifs are called by the script in question

Nope. There was no script in that last post. In fact we'll probably soon be told to "get a room".

AaronAgassi

9:21 pm on Jun 29, 2004 (gmt 0)

10+ Year Member



With border thickness set to zero I got:
style="border-style:solid; border-color:red;
added to all the inages, animated or static.
Still no help...

Bernard Marx

11:27 am on Jun 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That's because the border is set to zero. Any other border specs will be a waste of code. If you don't want to mess about with image borders, then you have to enclose the images in DIVs etc. I don't know anything else on the subject.

AaronAgassi

12:51 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



The animated gifs are already div enclosed, as closely as is possible to still contain all of the html size and position specifications regarding presentation of each image.

AaronAgassi

1:10 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



PS. now explicitly inserted:

0 px;

-into the statements, but still no help...

Bernard Marx

2:20 pm on Jun 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To summarise, the solution options are:
1. Define all dims explicitly; 'wrap' individual images closely in a container.
2. Do not set image borders to zero (either in HTML or CSS).

That always sorts out the problem, which only appears to happen in IE5.
Otherwise...dunno. Unless you are referring to a different problem. I'm talking about images breaking apart, and spreading over the page. However, it used to be the case that Netscape animated gifs differently to IE. It appeared that NN wasn't hiding the previous layer when playing the new over a constant background layer. So, many gifs with transparent areas on layers would look 100% pants on NN. I assumed they'd sorted this out in later versions.

AaronAgassi

3:40 pm on Jun 30, 2004 (gmt 0)

10+ Year Member



Sorry, I thought I was explicit that my problem is simply that the animated gifs simply do not animate while certain scripts are running. Also, I am running IE 6