GIF动画不玩刷新 [英] gif animation not playing on refresh
问题描述
我第一次查看页面用.gif动画它起着罚款页面加载(持续约2秒)。
First time I view the page with an animated .gif it plays fine on page load (lasts about 2 secs).
在刷新(F5),将.gif文件不再戏剧和只显示GIF动画的最后一帧。
On refresh (F5), the .gif no longer plays and only the last frame of gif animation is shown.
有什么我能做的做,以确保它起着每次?
Is there anything I can do do to make sure it plays everytime?
推荐答案
奇怪的行为,这是影响到每一个浏览器..结果
我通常用这个脚本(它使用jQuery)
Strange behavior that's affects every browser..
I usually refresh it manually with this script (it uses jQuery)
<img id="gif_animata" src="picturePath.gif">
<script type="text/javascript">
var gifSource = $('#gif_animata').attr('src'); //get the source in the var
$('#gif_animata').attr('src', ""); //erase the source
$('#gif_animata').attr('src', gifSource+"?"+new Date().getTime()); //add the date to the source of the image... :-)
</script>
这将刷新图像添加当前日期的src,所以浏览器会重新加载它,以为这是一个新的形象。
This will refresh the src of the image adding the current date, so the browser will re-load it, thinking that's a new image.
否则在PHP的方式(我preFER这一个):
Otherwise in PHP way (I prefer this one):
<img src="picturePath.gif?<?php echo date("Ymdgis");?>" />
//for the browser it will seems that's a new picture!
<img src="picturePath.gif?2012092011207">
这篇关于GIF动画不玩刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!