Want to blink the "image.gif" image for certain condition.
For example, if i upload the new data, then there will be dataNew.gif file, that will blink. Otherwise it will not blink.
Want to blink the "image.gif" image for certain condition.
For example, if i upload the new data, then there will be dataNew.gif file, that will blink. Otherwise it will not blink.
Add this to your page:
And addCode:<script type="text/javascript"> var hideorshow="hidden" function blinkImg(imgname) { var obj = document.images[imgname] obj.style.display=hideorshow if (hideorshow=="visible") { hideorshow="hidden" } else { hideorshow="visible" } } </script>name="whatyouwanttocallit"to your image tag and call the JS functionblinkImg('whatyoucalledtheimage')whenever you want it to blink.
Last edited by tech_support; 08-07-2007 at 07:39 AM. Reason: Corrected errors noted by John.
Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
Currently: enjoying the early holidays :)Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide
That won't blink. It won't do anything becausevar obj = document.images['imgname']will not represent any image passed to the function unless its name is literally 'imgname'. You should have left the quotes off. Even if it did 'work', it would take the image out of the page flow or put it into the page flow once and once only per execution, disrupting the flow of the document.
This works:
Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var blinkImg = function (imgname, s) { clearTimeout(blinkImg['blinking' + imgname]); var obj = document.images[imgname]; if (arguments[1] === 'blink') { obj.style.visibility = !(blinkImg[s + imgname] = !blinkImg[s + imgname])? '' : 'hidden'; blinkImg['blinking' + imgname] = setTimeout(function(){blinkImg(imgname, s);}, 350); } else { blinkImg['blink' + imgname] = false; obj.style.visibility = ''; } }; </script> </head> <body> <img name="blinker1" src="some.gif"><br> <input type="button" onclick="blinkImg('blinker1', 'blink');" value="Blink"> <input type="button" onclick="blinkImg('blinker1', 'stop');" value="Stop"> </body> </html>
Last edited by jscheuer1; 08-07-2007 at 08:37 AM. Reason: improve code
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
John - I'm a newbie with JavaScript. Can you please describe how I can run your blinking script automatically when the page loads? I've tried the window.onload command but haven't had any luck. Thanks!
Add the highlighted after the image (preferably just before the closing </body> tag) as shown.
NOTES: The buttons are no longer required, but may remain if desired. If the image is missing or doesn't load for some reason, the added code will do nothing.Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/loose.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> var blinkImg = function (imgname, s) { clearTimeout(blinkImg['blinking' + imgname]); var obj = document.images[imgname]; if (arguments[1] === 'blink') { obj.style.visibility = !(blinkImg[s + imgname] = !blinkImg[s + imgname])? '' : 'hidden'; blinkImg['blinking' + imgname] = setTimeout(function(){blinkImg(imgname, s);}, 350); } else { blinkImg['blink' + imgname] = false; obj.style.visibility = ''; } }; </script> </head> <body> <img name="blinker1" src="some.gif"><br> <input type="button" onclick="blinkImg('blinker1', 'blink');" value="Blink"> <input type="button" onclick="blinkImg('blinker1', 'stop');" value="Stop"><script type="text/javascript"> if(document.images['blinker1'].complete){ blinkImg('blinker1', 'blink'); } else { document.images['blinker1'].onload = function(){ blinkImg('blinker1', 'blink'); } } </script></body> </html>
- John________________________
Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate
Bookmarks