UPDATE, BASED ON FEEDBACK FROM OP:
I'm running up-to-date versions of Firefox, Chrome, and Safari on OS X and the Gifs do not ever freeze for me unless I click the "(Frozen) Gif" button on the jsfiddle, so this appears to be a localized glitch for the OP.
One possible reason is that browsers sometimes skip animating a Gif initially if they're very computationally busy.. E.g. lots of tabs are open, or inefficient JS is running elsewhere on the page.
ORIGINAL ANSWER:
Hopefully I'm understanding what you're looking for correctly - you would like:
- To show 1 gif and 2 radio buttons
- For clicking the radio buttons to switch which Gif is shown
- And, the ability to 'freeze' the Gif animation?
If that's incorrect let me know. :)
The code you've given already does (1) and (2) for me. I don't think there's any real way to freeze a Gif through Javascript, but you can kind of hack it together using the method described here (Stopping GIF Animation Programmatically)
I created a JSFiddle here:
Radio buttons 2 & 3 will swap out the Gif, and radio button 1 replaces the gif with a frozen facsimile. To "unfreeze" the gif, you would unfortunately need to entirely recreate the <img src="...">
element.
HTML:
<label><input type="radio" name="anima" onclick="freeze_gif(document.getElementById('imgC'))"/>(Frozen) Gif</label>
<label><input type="radio" name="anima" onclick="create_gif_1(document.getElementById('imgC'));" checked/>Gif 1</label>
<label><input type="radio" name="anima" onclick="create_gif_2(document.getElementById('imgC'));"/>Gif 2</label>
<br>
<img id='imgC' src='http://25.media.tumblr.com/tumblr_m5kv2t19Mm1rqk3zwo1_400.gif'>
JS:
function freeze_gif(i) {
var c = document.createElement('canvas');
var w = c.width = i.width;
var h = c.height = i.height;
c.getContext('2d').drawImage(i, 0, 0, w, h);
try {
i.src = c.toDataURL("image/gif"); // if possible, retain all css aspects
} catch(e) { // cross-domain -- mimic original with all its tag attributes
for (var j = 0, a; a = i.attributes[j]; j++)
c.setAttribute(a.name, a.value);
i.parentNode.replaceChild(c, i);
}
}
function create_gif_1(i) {
var img = document.createElement("img");
img.src = 'http://25.media.tumblr.com/tumblr_m5kv2t19Mm1rqk3zwo1_400.gif';
i.parentNode.replaceChild(img, i);
img.id = i.id;
}
//function create_gif_2(i) { ... same ... }
EDIT: I should add that the Gif-freezing trick is not supported by IE8