gif动画没有在刷新时播放

Fee*_*ney 14 animation refresh gif autoplay browser-refresh

我第一次使用动画.gif查看页面,它在页面加载时播放正常(持续约2秒).

在刷新(F5)时,.gif不再播放,只显示gif动画的最后一帧.

有什么我可以做的,以确保它每次播放?

小智 11

对于PHP来说,使用的更好的选择date("Ymdgis");是使用time(),如下所示:

<img src="picturePath.gif?<?php echo time();?>" />
Run Code Online (Sandbox Code Playgroud)


sek*_*kmo 8

影响每个浏览器的奇怪行为..
我通常使用此脚本手动刷新它(它使用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>
Run Code Online (Sandbox Code Playgroud)

这将刷新添加当前日期的图像的src,因此浏览器将重新加载它,认为这是一个新图像.

否则以PHP方式(我更喜欢这个):

<img src="picturePath.gif?<?php echo date("Ymdgis");?>" />

//for the browser it will seems that's a new picture!
<img src="picturePath.gif?2012092011207">
Run Code Online (Sandbox Code Playgroud)


小智 -2

您的浏览器可能只显示缓存的版本。尝试按住shift并刷新,看看是否有效。