Animated GIF images in hidden page elements
Here’s an HTML and IE issue that I haven't been able to figure out. In a number of my HTML forms I dynamically show and hide elements using the style tags within the JavaScript code:
document.getElementById('MainForm').style.display='none';
document.getElementById('WaitForm').style.display='inline';
This works great, except for an apparent bug in Internet Explorer that doesn’t want to display animated GIF images as animated once the image has been rendered into a container that is not visible.
Here is a a typical scenario: An order submission form when the application goes off to process credit cards and gives the user a 10 second ‘please wait’ interface. THe page starts out displaying the MainForm as visible, then when the order gets submitted it sets the MainForm display to 'none' and the WaitForm to 'inline' or '', which effectively swaps the displays.
It works great EXCEPT that Internet Explorer will not show animated GIF images as animated in the newly made visible panel. I’ve tried a number of approaches around this to force IE to refresh the image but none of them seem to work.
Here's the HTML for the WaitNote panel:
<div id="WaitNote" style="display:none" >
<p> </p>
<table height="300" border="1" cellpadding="25" align="center">
<tr><td valign="center" class="gridalternate">
<p>
<center>
<img id="WaitImage" src="images/pleasewait.gif">
<p>
<p> </p>
<span style="font-size:12pt;font-weight:bold;">
We're processing your credit card.</span><br>
This process may take a few seconds, so please be patient.
</center>
</td></tr></table>
<p>
</div>
function ShowWaitDisplay()
{
document.getElementById('MainForm').style.display='none';
document.getElementById('WaitNote').style.display='inline';
Img = document.getElementById('WaitImage');
Img.style.display="inline";
Img.src = "images/pleasewait.gif";
window.scrollTo(0,0);
return true;
}
As you can see I tried to explicitly reload the image and force the image style to be inline but that didn't help. I’ve also tried to set up the image without a SRC attribute to start with and load it later in the function, but this only causes IE to not display the image at all - it seems the page doesn't refresh.
Anybody know if there’s some way to force IE to refresh the document?
Of course this works just fine in FireFox any way that I try this, but it sure would be nice to get this to work in IE too. If I can’t I’ll have to go and resort to an IFRAME approach, which would make this a bit more complicated and also less browser compatible.
Other Posts you might also like
The Voices of Reason
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
[BTW "display:inline" is supported by IE, isn't the same as '' (as far as I know) and is very important (the diff between block and inline is something that is pretty much required knowledge if you're doing any CSS work at all).]
# re: Animated GIF images in hidden page elements
I need to look into the script issue. I tried running the form without hiding the panel and it comes up with the animating gif. Then when I explicitly set it to visible (calling the ShowWaitDisplay), the image stops. So I think you're on to something here.
Question is: Is there a way around this. This really sucks...
# re: Animated GIF images in hidden page elements
First add the IFRAME:
<iframe height="500" width="95%" ID="WaitFrame" src="WaitForm.htm" scrolling="no" frameborder="0" style="display:none">
</iframe>
Then the script:
function ShowWaitDisplay()
{
document.getElementById("MainForm").style.display="none";
IFrame = document.getElementById("WaitFrame");
IFrame.src = "waitform.htm"
IFrame.style.display = "inline";
window.scrollTo(0,0);
return true;
}
Note that both the frame and the script set the IFRAME source. This is the only way I could get both IE and Mozilla to properly render the frame. Leave the Src off the IFRAME and Mozilla will not display anything (apparently this is a refresh problem). Leave it off the script code and IE will not animate the image because apparently the display:none makes IE turn off animation even inside of a frame. With a static HTML page this doesn't matter I suppose, but with a dynamic page this would mean two loads of the page...
A dynamic page would have hte advantage that you could make it somewhat dynamic and pass different text into the form for the message.
# re: Animated GIF images in hidden page elements
The trick is to toggle the CSS visibility attribute as well as the display attribute.
// show gif
searchingimg.style.visibility = "visible";
searchingimg.style.display= "inline";
// hide gif
searchingimg.style.visibility = "hidden";
searchingimg.style.display= "none";
# re: Animated GIF images in hidden page elements
function show_progress()
{
var dv = document.getElementById('saveevent');
var pg = document.getElementById('progress');
if(dv && pg) {
dv.style.display = 'none';
pg.style.display = 'block';
}
setTimeout('document.images["pbar"].src = "images/progress_bar.gif"', 200);
}
# re: Animated GIF images in hidden page elements
This did the trick also by me:
setTimeout('document.images["pbar"].src = "images/progress_bar.gif"', 200);
Cheers all.
# re: Animated GIF images in hidden page elements
document.getElementById("myElement").innerHTML = "<img src='animation.gif'>";
It's not elegant, but it does the job.
# re: Animated GIF images in hidden page elements
Cheers, that worked a treat!
# re: Animated GIF images in hidden page elements
Great
Thanks
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Any Ideas?
# re: Animated GIF images in hidden page elements
If (Not Page.IsPostBack) Then Me.button.Attributes.Add "onclick", "do something()")
End If
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Any clues?
Thanks
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
<span id="WaitImage" <img src="images/pleasewait.gif"></span>
i got the same problem... and solved by wrapping with SPAN. IE sucks.
# re: Animated GIF images in hidden page elements
The problem is simply that IE doesn't render the image as animated cause it was invisible when it was rendered. So the solution is simple.
Lets say for example we are dealing with an image as follows :
<div id='myHiddeDiv' style='display:none'>
<img src='' id='myAnimatedImage'>
</div>
<input type='button' value='show image' onclick='showDiv();'>
<script languag='javascript'>
function showDiv()
{
document.getElementById('myHiddeDiv').style.display ="";
document.getElementById('myAnimatedImage').src = "http://www.nowhere.com/animatedGif.gif";
}
</script>
The solution described above will solve this problem because the browser only fetches the image once the element is visible. Hence no issues.
# re: Animated GIF images in hidden page elements
Sorry in the about post the following tag:
<script languag='javascript'>
is incorrect. The correction is as follows:
<script language='javascript'>
# re: Animated GIF images in hidden page elements
var old__doPostBack = __doPostBack;
__doPostBack = function(eventTarget, eventArgument)
{
old__doPostBack(eventTarget, eventArgument);
// your custom function calls go here
}
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
function showProcess()
{
if (Page_ClientValidate())
{
document.getElementById("spanProcess").style.visibility = "visible";
setTimeout("document.getElementById('pbar').src='/images/indicator.gif';",10);
setTimeout("z=document.getElementById('spanProcess');",1000);
}
return true;
}
# re: Animated GIF images in hidden page elements
Actually i m showing gif images in a table(HTML). They are working fine when they r shown first time on page means they r playing well.now when user clicks on a image this gif image(clicked) is shown in a popup window using js.at this moment the gifs on the parent page stop playing.Also this happens only in IE.It works fine in Firefox.
The setTimeout adviced in this post works fine with one image but i want all the images to stay playing after the popup appears.One more thing the url for src of imgs are retreived from database and this url is passed to the js at the time of popup.I can reload the parent page but I want to avoid it as I think if I only refresh the images on the page my task is done.
Thanx in advance.
Regards.
Bhushan.
# re: Animated GIF images in hidden page elements
Thank you very much whoever is the first discoverer. I just wanted to be so skillfull as this person.
Regards,
Sri.
# re: Animated GIF images in hidden page elements
<div id="progressBar" style="display:none;">
<img src="animatedBar.gif"/>
</div>
then in the onsubmit() of the form which does my file upload:
var div = document.getElementById('progressBar');
div.style.display = '';
setTimeout(200,'document.getElementById('progressBar').innerHTML = document.getElementById('progressBar').innerHTML);
The replacing of the innerHTML of the div by its own innerHTML seems to work, you only have to do it using setTimeout.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
<table>
<tr>
<td style="background:url('../path/to/image/animated.gif');"> </td>
</tr>
</table>
Now you hide/display the table with javascript and the animated gif will always be displayed in IE.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Right now I'm trying to do the xsl transformation on the server-side instead to speed things up (not a solution to the problem but it'll help hide the issue). The server-side works well and pretty quick too but the request.responseText cuts out when assigning it to a div's innerHTML (when using alert(this.req.responseText) it shows all of the html and doesn't cut it off). This is outside the scope of the Animated Gif image subject but maybe it'll help someone traversing the web for an answer.
# re: Animated GIF images in hidden page elements
More info here:
http://west-wind.com/weblog/posts/6951.aspx
Been there and gone through that same pain with figuring out how keep state in JavaScript <s>...
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Is it "use the timeout and don't worry about IE7" ?
Thanks.
# re: Animated GIF images in hidden page elements
a "onclick=foo()", and after I added the timeout line to the end of foo(), it worked.
# re: Animated GIF images in hidden page elements
Not sure what to do about IE 7 in this scenario.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
setTimeout(function() {
$('img').each(function() {this.src = this.src + '?random=' + new Date().getTime()})
}, 300);
Which would reset the src attribute for each image on the page with the same file plus ?random=<some random number> that would force the image to be reloaded.
This worked for me.
# re: Animated GIF images in hidden page elements
I'm a tester for sitebar.org,
I solved the issue for IE6+ at my testing page above.
SiteBar is an Open Source Software
feel free to view .js and .css source
it works without setTimeout().
Cheers,
Vlad
# re: Animated GIF images in hidden page elements
to see it in action
try to open bookmark folders
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
body.siteBar div#sb_main span#sb_label_loading
{
/*background: url('progress.gif') no-repeat fixed left;*/
height: 16px !important;
/*padding-left: 18px !important;*/
}
body.siteBar div#sb_main div#sbarBody span#sb_label_loading a.ajax
{
background: #316ac5;
color: white !important;
font-weight: bolder;
padding: 1px 0px !important;
text-decoration: none !important;
vertical-align: bottom !important;
}
/* background-image as animated GIF only works in IE
body.siteBar div#sb_main div#sbarBody div.tree span#sb_label_loading
{
background : #316ac5 url('progress.gif') no-repeat fixed left;
padding-left : 18px;
}
*/
************************************
in JS:
function SB_getJSData(label)
{
var obj = document.getElementById(label);
if (obj)
{
//alert('Javascript data for ' + label + ' not found!');
return obj.innerHTML;
}
//return obj.innerHTML;
}
the above function is referred to in another function
function SB_nodeReload(event, obj)
{
..................
..................
children.innerHTML = '';
for (var i=0; i<level; i++)
{
children.innerHTML += ' ';
}
children.innerHTML += '<span id="sb_label_loading"><img src="'+SB_getJSData('sb_skinDir')+'progress.gif" alt=""><a href="#a'+obj.id+'" class="ajax">' +SB_getJSData('sb_label_loading') + '</a></span>';
// Yes, this is an AJAX style of doing things
ohttp.onreadystatechange = function()
{
if (SB_xmlHttpReady())
{
var hdrIdx = ohttp.responseText.indexOf("\r");
var nid = ohttp.responseText.substr(1,hdrIdx);
//var children = document.getElementById('cn' + nid);
children.innerHTML = ohttp.responseText.substr('cn'+nid);
}
}
var acl = obj.getAttribute('x_acl');
url = 'index.php?w=sitebar_ajax'+
'&call=loadfolder'+
'&nid='+obj.id.substr(1)+
'&level='+level+
'&acl='+acl +
SB_appendPersistentParams();
SB_xmlHttpSend(ohttp, url);
}
}
}
*************************************
in HTML (generated by PHP script) just below BODY tag:
NOTE: THE PARENT CONTAINER IS HIDDEN, BUT NOT ITS CHILDNODES!
<div class="hidden">
<span id="sb_label_loading">Loading ...</span>
<span id="sb_loader">SB_nodeReload(n,n.parentNode)</span>
</div>
********************************
and all of the above is handled by prototype event-hadler and DOM-loader
AND class-OR-id-selectors
from my JS.API which I modified from
well known JS gurus:
/*
* (c)2006 Dean Edwards/Matthias Miller/John Resig
* Special thanks to Dan Webb's domready.js Prototype extension
* and Simon Willison's addLoadEvent
* For more info, see:
* http://dean.edwards.name/weblog/2006/06/again/
* http://www.vivabit.com/bollocks/2006/06/21/a-dom-ready-extension-for-prototype
* http://simon.incutio.com/archive/2004/05/26/addLoadEvent
*
* Thrown together by Jesse Skinner (http://www.thefutureoftheweb.com/)
*
* To use: call addDOMLoadEvent one or more times with functions, ie:
*
* function something() {
* // do something
* }
* addDOMLoadEvent(something);
*
* addDOMLoadEvent(function() {
* // do other stuff
* });
*
*/
function addDOMLoadEvent(func) {
if (!window.__load_events) {
var init = function () {
// quit if this function has already been called
if (arguments.callee.done) return;
// flag this function so we don't do the same thing twice
arguments.callee.done = true;
// kill the timer
if (window.__load_timer) {
clearInterval(window.__load_timer);
window.__load_timer = null;
}
// execute each function in the stack in the order they were added
for (var i=0;i < window.__load_events.length;i++) {
window.__load_events[i]();
}
window.__load_events = null;
};
// for Mozilla/Opera9
if (document.addEventListener) {
document.addEventListener("DOMContentLoaded", init, false);
}
// for Internet Explorer
/*@cc_on @*/
/*@if (@_win32)
document.write("<scr"+"ipt id=__ie_onload defer src=javascript:void(0)><\/scr"+"ipt>");
var script = document.getElementById("__ie_onload");
script.onreadystatechange = function() {
if (this.readyState == "complete") {
init(); // call the onload handler
}
};
/*@end @*/
// for Safari
if (/WebKit/i.test(navigator.userAgent)) { // sniff
window.__load_timer = setInterval(function() {
if (/loaded|complete/.test(document.readyState)) {
init(); // call the onload handler
}
}, 10);
}
// for other browsers
window.onload = init;
// create event function stack
window.__load_events = [];
}
// add function to event stack
window.__load_events.push(func);
SB_preloadImages(images);
}
addDOMLoadEvent(function () {
function attachEH(o, e, f)
{
if(o.attachEvent) o.attachEvent("on"+e,f);
else o.addEventListener(e, f, true); //synchronous AJAX call
}
function detachEH(o, e, f)
{
if(o.detachEvent) o.detachEvent("on"+e,f);
else o.removeEventListener(e, f, true);
}
var Behaviour = {
list: {},
handle : function (e) {
if (!e) e = window.event;
var n = e.srcElement || e.target;
while(n && document.domain) {
try { Behaviour.list[e.type+"__"+n.className](n) } catch (err) {};
try { Behaviour.list[ e.type+"_"+n.id](n) } catch (err) {};
if (n.last) { n.last = null; break; }
n = n.parentNode;
}
},
start : function () {
//start handlers, here you can attach what ever event handlers you need
var d = db || de;
attachEH( d, 'mousedown', Behaviour.handle );
attachEH( d, 'mouseover', Behaviour.handle );
attachEH( d, 'mouseout', Behaviour.handle );
attachEH( d, 'mouseup', Behaviour.handle );
attachEH( d, 'click', Behaviour.handle );
attachEH( d, 'keydown', Behaviour.handle );
attachEH( d, 'keypress', Behaviour.handle );
attachEH( d, 'keyup', Behaviour.handle );
attachEH( d, 'contextmenu', Behaviour.handle );
attachEH( d, 'focus', Behaviour.handle );
attachEH( d, 'mousemove', Behaviour.handle );
attachEH( d, 'dragstart', Behaviour.handle );
},
end : function () {
//end handlers, here you can detach what ever event handlers you need
var d = db || de;
detachEH( d, 'mousedown', Behaviour.handle );
detachEH( d, 'mouseover', Behaviour.handle );
detachEH( d, 'mouseout', Behaviour.handle );
detachEH( d, 'mouseup', Behaviour.handle );
detachEH( d, 'click', Behaviour.handle );
detachEH( d, 'keydown', Behaviour.handle );
detachEH( d, 'keypress', Behaviour.handle );
detachEH( d, 'keyup', Behaviour.handle );
detachEH( d, 'contextmenu', Behaviour.handle );
detachEH( d, 'focus', Behaviour.handle );
detachEH( d, 'mousemove', Behaviour.handle );
detachEH( d, 'dragstart', Behaviour.handle );
}
};
/* usually we start event handlers when document.body is loaded */
Behaviour.start();
//Behaviour.end();
/* examples */
/* command hash name syntax: <event>_<id> or <event>__<className> */
Behaviour.list = {
//element with class "foo" 2 "underscore"
//............
click__loader:function(n){ SB_nodeReload(n, n.parentNode) || SB_getJSData('sb_loader'); location.hash='#an'+n.parentNode.id.substr(1); n.last = true; },
//....................
//element with id "foo" 1 "underscore"
//.................
click_btnCollapse:function(n){ SB_collapseAll(); n.last = true; },
click_btnReloadAll:function(n){ SB_reloadAll(); n.last = true; },
click_btnReload:function(n){ SB_reloadPage(); n.last = true; }
}
});
//Special Operators:this Operator
//http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Operators:Special_Operators:this_Operator#Method_binding
//The distinction between methods and functions is made only when they are called:
//method calls pass the "parent object" as this,
//while function calls pass the global object as this.
Best regards,
Vlad
# re: Animated GIF images in hidden page elements
var d= de || db;//means document.documentElement || document.body
Vlad
# re: Animated GIF images in hidden page elements
I am using an animated gif which shows that the page is loading.In the design it is animating but when the application is run only the image appears ...it is not animating.I dont want to use ajax framework.is there aany way to make this possible
# re: Animated GIF images in hidden page elements
setTimeout()
Any other suggestions anyone?
# re: Animated GIF images in hidden page elements
# SO SIMPLE TO FIX GUYS....
Just make sure the width & height of the div matches the height/width of the background image.
<div id="processing"></div>
.processing {
background: url('/path/to/processing-anim.gif') 50% 50% no-repeat;'
width:250px; height:45px;
}# re: SO SIMPLE TO FIX GUYS....
Should be: #processing { ... } not .processing { ... }
# re: Animated GIF images in hidden page elements
<input type=submit value=Update onClick="document.getElementById('uploading').style.visibility='visible';document.getElementById('uploading').innerHTML='<font size=2>Uploading...</font><br><img src=images/uploading.gif>'"> <div id=uploading style='visibility: hidden'> <font size=2>Uploading...</font><br> <img src=images/uploading.gif> </div>
I'm guessing this will make the div visible first then load the image which is key to working around this bug in IE.
I also found that if I don't call the image from within the div and just rely on the js to grab it, the image is not animated in Firefox.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
<script type="text/javascript">
<!--
function showLayer(layerid) {
layer = document.getElementById(layerid);
layer.style.display="inline";
layer.style.visibility = "visible";
setTimeout('document.images["loading"].src = "images/loading.gif"', 900);
}
//-->
</script>
<div id="content"><span id="about"><img src="/images/loading.gif" name="loading"/></span>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"
onSubmit="showLayer('about')">
Obviously you need to put this lot in the appropriate places, and excuse me if this looks terrible, but i really am no javascripter at all, all i know is i spent a day hacking away at it and this is what worked in the end. Good Luck.
# re: Animated GIF images in hidden page elements
SO SIMPLE TO FIX GUYS....
by mikeJune 29, 2007 @ 3:32 pm
...worked perfectly! Many thanks!
# re: SO SIMPLE TO FIX GUYS....
Nice and elegant solution, and... Works!!
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
I think the difference here is that the image is initially shown invisibly, so it never was enabled by IE.
60 messages later and it looks like there's still no reliable solution to this problem. Short of the smart ass remark to run asynchronously which is obvious.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
I've tested it in IE6, IE7, Firefox 2.0.0.6, Safari 3.0.3
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Load Box</title> <!-- Set Javascript function to make animation appear --> <script type="text/javascript"> // uses a combination of two different javascript functions from // Tanora and helmus, see http://forums.tizag.com/showthread.php?t=2507 // progress bar gifs taken from helmus' page at http://www.biodanza.be/jsgif.php // image url's are: http://www.biodanza.be/images/loaded_1.jpg // and http://www.biodanza.be/images/loaded_0.jpg function show_progress() { var load = document.getElementById('loadbox'); load.style.display = 'block'; } var speed =70; function animategif(id,direction){ // size relates to the number of gif's used in the progress bar // you'll need a pair of gifs (loaded_1, and loaded_0) for each one. size= 7; if(id<size && direction){ document.getElementById("0progres"+id).style.display='none' document.getElementById("1progres"+id).style.display='' setTimeout("animategif("+(id+1)+",1)",speed); }else if(direction){ animategif(0,0) } if( id<size && (!direction) ){ document.getElementById("0progres"+id).style.display='' document.getElementById("1progres"+id).style.display='none' setTimeout("animategif("+(id+1)+",0)",speed); }else if(!direction){ animategif(0,1) } } </script> <!-- Set stylesheet to make loader box invisible until Javascript calls for it --> <style type="text/css"> div#loadbox { border: 1px solid #000000; width: 200px; height: 50px; padding: 10px; display: none; background-color: #FFFF99; position:absolute; z-index:9999; left: 419px; top: 279px; } .style1 { font-family: Arial, Helvetica, sans-serif; font-size: 10px; } </style> </head> <body onload="animategif(0,1);"> <!-- add the show_progress function to the link --> <a href="[link to page that takes an age to load]" onclick="show_progress();">Test</a> <BR> <DIV id="loadbox"> <div align="center"><span class="style1">Processing<br> <BR> <img name="progres" style="display:" id="0progres0" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres0" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres1" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres1" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres2" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres2" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres3" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres3" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres4" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres4" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres5" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres5" src="loaded_1.jpg" width="13" height="13"><img name="progres" style="display:" id="0progres6" src="loaded_0.jpg" width="13" height="13"><img name="progres" style="display:none" id="1progres6" src="loaded_1.jpg" width="13" height="13"> </span><br> </div> </DIV> </body> </html>
# re: Animated GIF images in hidden page elements
...
<div id="processingDiv">
<span id="processing" class="processing">
<img id="loading" src="img/kyticka.gif" />
</span>
</div>
...
onclick="showProcessing('processing');"
...
function showProcessing(strObject){
var object = document.getElementById(strObject);
if (window.innerHeight)
{
pos = window.pageYOffset
}
else if (document.documentElement && document.documentElement.scrollTop)
{
pos = document.documentElement.scrollTop
}
else if (document.body)
{
pos = document.body.scrollTop
}
object.style.display = 'inline';
object.style.visibility = 'visible';
//object.style.top = (self.screen.height - pos)/2 - 48;
object.style.top = pos + 150;
//object.style.left = window.pageXOffset + 350 - 74;
setTimeout('document.images["loading"].src = document.images["loading"].src', 1);
}
# re: Animated GIF images in hidden page elements
My Scenario for wait image display consists three page. (I work in ASP.Net)
Page first (From other sites) will have links for second page. Second page will do some processing required for third page. This intermediate page opens the final third page using javascript.
I am displaying the wait image on the second page. I can not put the wait image code on third page.
The second page opens the a blank window using window.open.
Then I write the wait image code into the window.document object. Wait image gets displayed.
Finally redirect to third page by changing the location.href of the blank window.
The wait image is displaying without animation. I have tried with setTimeout/background image. Neither of them worked for me in any browser. Here is the code used.
<script language="javascript"> var win = window.open(''); var doc = win.document; doc.open(); <%Response.Buffer = true;%> doc.writeln('<html>'); doc.writeln('<body><div id="divLoad"><img src="wait_loading.gif" width="300" height="261" alt="Loading..." ></div>'); doc.writeln('<br><br>'); doc.writeln('</body></html>'); <%Response.Flush();%> doc.close(); win.location.href = ThirdPageurl; window.opener = win; window.close(); </script>
Will you please tell me what is wrong with the code and what should be done for animating the image?
Please help me out. Client is eating my lil head. Your suggestions would be greatllyyy aprreciated.
# re: Animated GIF images in hidden page elements
# Mike's Simple Solution
Getting an image to show ONLY upon submit and ONLY on the same page as the original submit.
# JayJuly's snippet did the trick for me
Very easy to implement also.
**********************************************************************
re: Animated GIF images in hidden page elements
by JayJuly 18, 2007 @ 9:10 am
I'm not sure why Richard's idea isn't working for everyone... I have used it and it works fine on Firefox and IE7. This is how I did it:
<input type=submit value=Update onClick="document.getElementById('uploading').style.visibility='visible';document.getElementById('uploading').innerHTML='<font size=2>Uploading...</font><br><img src=images/uploading.gif>'">
<div id=uploading style='visibility: hidden'>
<font size=2>Uploading...</font><br>
<img src=images/uploading.gif>
</div>
I'm guessing this will make the div visible first then load the image which is key to working around this bug in IE.
I also found that if I don't call the image from within the div and just rely on the js to grab it, the image is not animated in Firefox.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Update function:
1st: include prototype.js:
<script src="includes/prototype.js" type="text/javascript"></script>
2nd: in the header or on a separate .js page:
function showLoader() {
var url = './includes/image_loading.php'; //the location of a page to load
var pars = null ;//any parameters you want to add
var target = 'main-image';//the div of the image to replace or add too
var myAjax = new Ajax.Updater(target, url, {method: 'get',
parameters: pars,
onComplete: function() {
document.myForm.submit()
}});
3rd:
your form:
<form name="myForm" action="index.php" method="post">
...
<input type="submit" onclick="showLoader();return false;" />
}
That seemed to do the trick for me in ie7 and everything else:
example at: www.printmybaby.com/index.php?p=products&id=67
# re: Animated GIF images in hidden page elements
document.getElementById('element').style.display = "";
document.form.submit();
to this:
document.form.submit();
document.getElementById('element').style.display = "";
And it worked fine.
# re: Animated GIF images in hidden page elements
This made it work for me in IE 8. The trick seemed to be, as someone said, add a random url to the image:
function showFormProgress(hideElementID, displayElementID, progressImgElementID) {
var hideElement = document.getElementById(hideElementID);
var showElement = document.getElementById(displayElementID);
var animGif = document.getElementById(progressImgElementID);
if (hideElement && showElement) {
hideElement.style.display = 'none';
showElement.style.display = '';
}
if (animGif) {
setTimeout(function() { animGif.src = animGif.src + "?rnd" + new Date().getTime() }, 300);
}
}
# re: Animated GIF images in hidden page elements
I have been reading through your post for the past one month and implementing yours as well as others methods to make the GIF animate in IE7 but it wudn't. Kindly help me out.
Mine is not event driven as in, when the page loads, it does lots of processing at the server side and once the processes get over a result page is displayed. I want to show an animated gif file when the processes run. But I was able to see only a single frame of it. I have tried, setTimeout, Mike's solution of CSS editing, innerHTML, iframes, display gif through javascript..
Please reply with some possible solution.
thanks!
Sanjay
# re: Animated GIF images in hidden page elements
I don't know if u have got any solution but here is some way i solved this problem,
Response.Write("<div id='mydiv' STYLE='FONT-WEIGHT: bold; FONT-SIZE: 10pt; LEFT: 20px; COLOR: black; FONT-FAMILY: Verdana; POSITION: absolute; TOP: 40px; TEXT-ALIGN: center() ' >");
Response.Write(" ");
Response.Write("</div>");
Response.Write("<script> var mydiv = document.getElementById('mydiv'); mydiv.innerHTML = '';</script>");
Response.Write("<script language=javascript>");
Response.Write("function ShowWait()");
Response.Write("{");
Response.Write("mydiv.innerHTML = \"<img src='animatedImage.gif' border='0'>\";}");
Response.Write("function StartShowWait(){mydiv.style.visibility = 'visible';ShowWait();ShowWait();}");
Response.Write("function HideWait(){mydiv.style.visibility = 'hidden';window.clearInterval();}");
Response.Write("StartShowWait();</script>");
I have put this code in page load before anything else is executed, then write your line of code and at the end write these two lines of code.
Response.Flush();
Response.Write("<script language=\"javascript\">HideWait();</script>");
# re: Animated GIF images in hidden page elements
I've had this problem tried all possible solutions until i set the z-index to 9999:
function showWait() {
if ($get('<%= imageFile.ClientID %>').value.length > 0) {
$get('ImageUploading').style.display = 'none';
$get('ImageUploadProgress').style.display = 'block';
$get('ImageUploadProgress').innerHTML = '<div id="ProgressDiv" style="width:280px;text-align:center;margin-bottom:10px;z-index:9999;">Uploading Image <br /> <img src="progressbg.gif" /></div>';
}
}
# re: Animated GIF images in hidden page elements
My latest attempt does not work at all; just not getting this one:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Load Box</title> <!-- Set Javascript function to make animation appear onsubmit --> <script type="text/javascript"> function showFormProgress(hideElementID, displayElementID, progressImgElementID) { var hideElement = document.getElementById(hideElementID); var showElement = document.getElementById(displayElementID); var animGif = document.getElementById(progressImgElementID); if (hideElement && showElement) { hideElement.style.display = 'none'; showElement.style.display = 'block'; } if (animGif) { setTimeout(function() { animGif.src = animGif.src + "?rnd" + new Date().getTime() }, 300); } } </script> </head> <body> <form id="hideElementID" action="http://72.155.252.88" onsubmit="showFormProgress();"> <input type="text" name="psword" size="25" style="height:25px; font-size:22px;" /> <input type=button value="submit the form" onclick="showFormProgress();"> </form> <BR> <DIV id="displayElementID" style="display:none;"> Loading:<br/> <img id="progressImgElementID" src="images/i_animated_loading_32_2.gif" id="loading"> </DIV> </body> </html>
This one works the best so far, but still have the issue with the enter button:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Load Box</title> <!-- Set Javascript function to make animation appear onsubmit --> <script type="text/javascript"> function form_submit() { var load = document.getElementById('loadbox'); document.form1.submit(); load.style.display = 'block'; load.src = 'images/i_animated_loading_32_2.gif'; } </script> <!-- Set stylsheet to make loader box invisible until Javascript calls for it --> <style type="text/css"> div#loadbox { border: 1px solid #000000; width: 200px; height: 50px; padding: 10px; display: none; } </style> </head> <body> <!-- I used a random IP address for this test so submission would take moments while I watched the loader animation --> <form name=form1 action="http://72.155.252.88" onsubmit="form_submit();"> <input type="text" name="psword" size="25" style="height:25px; font-size:22px;" /> <input type=button value="submit the form" onClick="form_submit();"> </form> <BR> <DIV id="loadbox"> Loading:<BR> <img src="images/i_animated_loading_32_2.gif" id="loading"> </DIV> </body> </html>
Can anyone tell this n00b what he's doing wrong?
# re: Animated GIF images in hidden page elements
Thank you very much for your help!! Sorry for the prolonged delay to reply as I checked this forum only now. I will go through this and will let you know the result. Again thanks a tom for your time and effort!
Sanjay
# re: Animated GIF images in hidden page elements
I collect the data from first page, redirecting to second where I am showing wating message with animated jif,(redirecting from second to thired page through javascript using window.location.href) still validate the data on thired page.all validations are done on thired page. and after validation I am showing the related information on fourth page.
by using timeout, the image is animating but not going for validations(on thired page).
if I comment the timeout then goes for validation but didnt animate the image.
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> </asp:UpdatePanel> <asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1"> <ProgressTemplate> <img runat="server" src="~/Images/load.gif" /> </ProgressTemplate> </asp:UpdateProgress>
if I use the code above it works for firefox but gives problem with IE.
working on issue from last week,still not able to resolved. please give some solution ASAP, client is wating for the same. so plz suggest ASAP.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Today I disovered animated gif are not working both on IE 7 and FF3 when contents of webpage is run locally on the machine (localhost) instead of running it online.
I'm clueless aboyt the reason, maybe somone could halp.
Anyone can easily test this by running this webpage
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Animated gif not working on localhost</title>
<script type="text/javascript">
var flag;
function ToggleAnimatedGifNotWorking()
{
var el = document.getElementById("animated_gif");
if(flag)
el.style.background = "url(arrow.gif) no-repeat";
else
el.style.background = "url(arrow_on.gif) no-repeat";
flag = !flag;
window.setTimeout("ToggleAnimatedGifNotWorking()", 2000);
}
window.setTimeout("ToggleAnimatedGifNotWorking()", 2000);
</script>
</head>
<body>
<h4>The arrow below is as animated gif that should rotate of 90 degrees every 2 seconds, it does work when file in on online on server, but it does not work when file is downloaded on localhost. Both on IE (Internet Explorer 7) and FF (FireFox 3)</h4>
<div id="animated_gif" style="padding: 20px;"> </div>
</body>
</html>Animated gif arrows and page can be found here: http://www.vanylla.it/test-animated-gif/animated-gif-not-working-on-localhost.html
# re: Animated GIF images in hidden page elements
Basically I am creating an arbitrary parameter with a random value to append to the image URL.
<div id="curtain" style="visibility:hidden" > <img id="spinner" class="hourglass" src = '/images/ajax-loader.gif' /> </div> <script type="text/javascript"> function showCurtain () { var curtain= document.getElementById('curtain') var spinner = document.getElementById('spinner') spinner.src = '/images/ajax-loader.gif?p=$RandomGuid' curtain.style.visibility='visible'; } </script>
where $RandomGuid is generated server side per each page request. It seems like the result is pretty consistent. I had the impression that it doesn't have to do much with the submit() button being pressed but with the fact that the image is cached, so by applying a fake parameter I force IE to refresh the image everytime.
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
After a weekend of starting out with a popup html window and trying to work around the popup blocking of IE and Firefox, I decided to shift a less intrusive upload progress frame. Which all appeared to work seamlessly when uploading a new image in Firefox. Then only to find the .gif won't animate in IE.
Which brings me here with my head about to explode. Have tried the above methods and they're not working for me. Obviously I'm missing something. Could I get help with this. I'm using the <form> onClick to trigger the image upload and to launch the progress frame.
<script type="text/javascript"> function popup() { document.getElementById('popup').style.display='block'; } </script> <div id="overlay"></div> <div id="popup"><span>Please wait while we process your request... <br /> <img src="{template_url}/images/uploading.gif" width="128" height="15" /></span></div> <input type="submit" name="uploadbutton" value="{lang_submit}" class="button" onClick= "popup();" />
and my CSS
#popup {
display: none;
position:absolute;
top: 50%;
left: 50%;
height:150px;
width: 300px;
margin-left: -150px;
text-align:center;
border:1px solid #666666;
z-index:15;
background-color: #FFFFFF;
padding-top: 50px;
}Thanks, Wayne
# re: Animated GIF images in hidden page elements
Richard
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
by Paperino June 03, 2009 @ 9:26 pm
I found a simpler solution. It seems that it works with IE7/IE8 as well.
Basically I am creating an arbitrary parameter with a random value to append to the image URL.
<div id="curtain" style="visibility:hidden" >
<img id="spinner" class="hourglass" src = '/images/ajax-loader.gif' />
</div>
<script type="text/javascript">
function showCurtain () {
var curtain= document.getElementById('curtain')
var spinner = document.getElementById('spinner')
spinner.src = '/images/ajax-loader.gif?p=$RandomGuid'
curtain.style.visibility='visible';
}
</script>
Just a heads up and a thanks. This worked and fixed the problem for IE7/8. However it opened a new one of Firefox not liking the random string on the end of the gif and displayed nothing at all!. The way I fixed this was to set the background image of the first div to be the image (without random string) and then the background image of the second div to be the image (with the random string).
<script type="text/javascript">
function showDiv() {
var randomString1 = randomString();
document.getElementById('loading').style.display = 'block';
document.getElementById('loading').style.visibility = 'visible';
document.getElementById('loading').style.backgroundImage = 'url(ajax-loader.gif)';
document.getElementById('loadingImage').style.backgroundImage = 'url(ajax-loader.gif?p=' + randomString1 + ')';
}
function randomString() {
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
var string_length = 5;
var randomstring = '';
for (var i = 0; i < string_length; i++) {
var rnum = Math.floor(Math.random() * chars.length);
randomstring += chars.substring(rnum, rnum + 1);
}
return randomString;
}
</script>
In firefox, this shows the 'loading' div with background, but as the random string "breaks" the 'loadingImage' image, the second image is not shown.
In IE, the first one shows as a static image, but the second is displayed over the top and animates!
# re: Animated GIF images in hidden page elements
<div id="loading">
<div id="loadingImage">
</div>
</div>
#loading { width:220px; height:19px; display:none; visibility:hidden; } #loadingImage { width:220px; height:19px; }
# re: Animated GIF images in hidden page elements
<div id="contentPanel"> page content before animated gif is to be shown </div> <div id="loadingPanel"> <img id="loadingImage" alt="Loading..." src="loading.gif" /> </div>
$("#content").hide(); $("#loadingPanel").show("fast", function() { $("#loadingImage").attr("src", $(this).attr("src")); });
# re: Animated GIF images in hidden page elements
$("#contentPanel").hide();
# re: Animated GIF images in hidden page elements
http://www.reconn.us/content/view/37/47/
Hope it helps.
# re: Animated GIF images in hidden page elements
Here's my HTML code:
<div id="img1" style="position:relative; left:0; top:0; width:100; height:100"> <img name="stdimg" border=0 src="assets/std.png" alt="Standard img" width=100 height=100 /> <div class="glitter"> <a href="#" onMouseover="changeView();" onMouseout="revertView();"> <img id="glitterimg" name="glitterimg" border="0" src="assets/blank.gif" alt="Fairy-dust img" width="100" height="100" /> </a> </div> </div>
Javascript:
if (document.images) { std = new Image; effect = new Image; std.src = "assets/blank.gif"; } function changeView() { /* Do function when using IE browser */ /* test for MSIE x.x */ if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { /* capture x.x version portion and store as a number */ var ieversion=new Number(RegExp.$1); if (ieversion>=6); document.getElementById('glitterimg').src = “assets/animation-test.gif”; } else { /* Do function when using any other browser */ document["glitterimg"].src = “assets/animation-test.gif”; } } function revertView() { document["glitterimg"].src = std.src; }
I have a standard image (that should never change) and I want to have a glitter effect to play on top of standard image when rollover occurs. Trying to assign "glitterimg" a transparent gif to begin with and then replace it with "animation-test.gif" on rollover. The changeView function is trying to determine if IE browser, as I found browsers need different document callout to work (they worked when separated) but the if-then part is giving me fits.
Help on sorting this out would be greatly appreciated.
Thanks, Bill
# re: Animated GIF images in hidden page elements
So, it actually is plain simple. Add the code at the moment you want it to be displayed.
# re: Animated GIF images in hidden page elements
CSS
.hideProgress { display: none } .showProgress { position: absolute; left: 482px; margin-left: -80px; display: block }
JavaScript
function submitBtnClicked() { var item = document.getElementById( "loadingImage" ); if (item) { item.className = 'showProgress'; setTimeout( 'document.getElementById( "loadingImageSrc" ).src = "images/loading.gif"', 200 ); } }
HTML
<div id="loadingImage" class="hideProgress"> <img src='' id='loadingImageSrc'> </div>
# re: Animated GIF images in hidden page elements
to resolve this please use jQuery progress bar.
please visit here for complete example
http://www.codeproject.com/KB/progress/JQueryProgressBar.aspx
# re: Animated GIF images in hidden page elements
$("#loadingPanel").hide();
Other than that, here is his code repeated again:
<div id="contentPanel"> page content before animated gif is to be shown </div> <div id="loadingPanel"> <img id="loadingImage" alt="Loading..." src="loading.gif" /> </div>
$("#contentPanel").hide(); $("#loadingPanel").show("fast", function() { $("#loadingImage").attr("src", $(this).attr("src")); });
Thanks!
# re: Animated GIF images in hidden page elements
Thanks!
# re: Animated GIF images in hidden page elements
I have "wait.gif" and a copy called "wait2.gif".
When you submit the form, just switch to another image. You can change CSS:display to show and hide image you want.
My JS file using jQuery
================
${n}.jQuery(".loadingImage").removeClass("loadingImage").addClass("loadingImage2");
My css file
========
.loadingImage
{
width:20px; height:20px; background: url(../images/wait.gif) no-repeat center center;
}
.loadingImage2
{
width:20px; height:20px; background: url(../images/wait2.gif) no-repeat center center;
}
My html
=======
<span><div class="loadingImage"> </div></span>
Hope it resolves the issues.
# re: Animated GIF images in hidden page elements
<!--/*--><![CDATA[/*><!--*/ if (document.getElementById("safeForm4b").submitted.value == "false") { document.getElementById("safeForm4b").submitted.value = "true"; setTimeout('document.getElementById("safeForm4b").submit()', 100); }else{ document.getElementById("toHide").style.display="none"; }/*-->]]>*/
Can you please inform me what i need to do
# re: Animated GIF images in hidden page elements
setTimeout('document.getElementById("safeForm30").src', 100);
this displays the image but not going for the next page. It shows only animated image.
# re: Animated GIF images in hidden page elements
Many thanks
Don
# re: Animated GIF images in hidden page elements
In your submit, click, or whatever javascript handler function, append a querystring with a unique value to your animated image's url.
So in @Rick Strahl's original example, you'd do this...
function ShowWaitDisplay() { document.getElementById('MainForm').style.display='none'; document.getElementById('WaitNote').style.display='inline'; Img = document.getElementById('WaitImage'); //begin my changes //Img.src = "images/pleasewait.gif"; //instead of the above line, do this... Img.src = "images/pleasewait.gif?z=" + new Date().getTime(); //using current time as my unique value //end my changes window.scrollTo(0,0); return true; }
# re: Animated GIF images in hidden page elements
# re: Animated GIF images in hidden page elements
Just added his code after setting the visibility of the element to true.
showWaitPage =function { blehbleh your code bone.elem.style.visibility = "visible";//the function ended here document.getElementById("YourElement").innerHTML = "<img src='yourGif.gif'>";
Thanks all and hope this works for most people!
# re: Animated GIF images in hidden page elements
A bit of tweaking and this now correctly shows the animated gif for me in all browsers:
HTML:
<div id="veil" style="position: relative; display: block; left: -9999px;"> <div id="progressBar"> <img src="/images/blank.gif" id="animatedBar" /> </div> </div> <a href="#" onclick="veilizer(); return false;">Go!</a>
Javascript:
window.onload = function() { setTimeout(function() { document.getElementById('animatedBar').setAttribute('src','/images/green-bar.gif'); },200); function veilizer() { document.getElementById('veil').style.left = "0"; document.getElementById('progressBar').innerHTML = "<img src='/images/green-bar.gif' id='animatedBar' />"; setTimeout(function( { document.getElementById('animatedBar').setAttribute('src','/images/green-bar.gif'); },20); };
# re: Animated GIF images in hidden page elements
for me this approach worked(vs 2008) :
aspx page:
<asp:Button ID="Button1" runat="server" Text="Button" /> <div id="loading1" class="Loading" style="visibility:hidden;margin-top:-12px;"> <img src='images/LoginLoader.gif' alt="loading" /> </div>
In Page_Load (vb):
Button1.Attributes.Add("Onclick", String.Format("Redirect('{0}')", Button1.ClientID))
Javascript:
<script type="text/javascript"> function Redirect(Control) { document.getElementById("loading1").style.visibility = 'visible'; if (navigator.appName == 'Microsoft Internet Explorer') { document.getElementById("loading1").innerHTML = "<img src='images/LoginLoader.gif' />"; } document.getElementById(Control).style.visibility = 'hidden'; } </script>
I've tried it in latest FF, Chrome, Opera and IE 9.0.
Hope it helps.
Cheers.
# re: Animated GIF images in hidden page elements
Html
<div id="divCont"> <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CssClass="navButton" OnClientClick="ShowProgCont()" /> </div> <div id="divProgCont" runat="server" clientidmode="Static" style="display:none;"> Please Wait...<br /> <img src="" alt="loading" height="50px" width="50px" id="imgLoading" /> </div>
Javascript
function ShowProgCont() { $get('imgLoading').src = '../images/BusySign.gif'; $get('divProgCont').style.display = 'block'; return false; }
# re: Animated GIF images in hidden page elements
Javascript
<script type="text/javascript"> function progresBar(){ var browser = navigator.appName; if(browser == 'Microsoft Internet Explorer'){ var bar = document.getElementById('yourElementID'); var img = document.getElementById('yourImageElementID'); bar.style.display = 'inline'; img.src="yourImageDirectory/bigrotation2.gif"; }else{ document.getElementById('yourElementID').style.display = 'inline'; } } </script>
HTML
<div class="texto" id="yourElementID" style="display: none"> <input type="image" id="yourImageElementID" name="image" src="imagens/estrutura/bigrotation2.gif" style="margin-left: 150px; margin-right:10px; position: relative;top:10px" /> File in process. Wait... </div>
And the .gif animation is working in all browsers.
# re: Animated GIF images in hidden page elements
document.getElementById('MainForm').style.display='none';
document.getElementById('WaitNote').style.display='';
I had thought inline was among the unsupported tags in IE like inherit and collapse. I will have to play around with that one.