• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

making gif animation run once then go back to default image

 
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an image tag on a page, and through java script I change the image to different gifs depending on triggers from the user (onFocus, onmouseover, etc). So here are some of the events:





So say the user triggers the first event, which changes the image to test.gif. What if I only want this gif to run it's animation one time, then go back to the previous image that it had replaced? Is there a way to control this?

Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no way to know anything about the animation within a GIF.

If you know the duration of the animation, you might be able to guess when it starts and ends, but it won't be deterministic.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easiest solution would be to alter the gif image's last frame to be the default image.

Eric
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I made a gif with real pics using this site: http://gickr.com/

and it made the gif just fine, but it loops through the animation over and over. So even if I were to make the last piece of the gif the original pic, the loop would start again and keep cycling through the animation. Is there a way to have it cycle only once and then stop?

Or is there some way to add in a count for the javascript to pause, during which time the gif will cycle through, then at the end of that countdown, the image can be replaced by the original image? SOmething like this in pseudo:

 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess the basic question would be, can you make the gif loop through it's frames only one time and stop rather than loop repeatedly.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use a GIF creation tool such as ImageReady to control the animation.
 
Matt Kohanek
Village Idiot
Posts: 484
jQuery Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've heard of that, I will look into it, thanks
 
If you live in a cold climate and on the grid, incandescent light can use less energy than LED. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic