Reputation: 1574
I have set GIF Image and its working fine but i have one query regarding it and that is how can i restart that GIF image after some time without refreshing page.
I have search alot but any solution is not working for me.
I have set code like :
<script type="text/javascript">
jQuery('document').ready(function(){
function func() {
//alert('Here');
var d = new Date();
var img = new Image();
img.src = 'http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif';
jQuery("#gifimg").attr("src", img.src + '?s=' + d.getTime());
timer = setTimeout(func, 30000)
}
var timer = setTimeout(func, 30000)
/*setInterval(function(){
//alert('hy');
var d = new Date();
// var img_path = 'http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif?' + d.getTime();
var img = new Image();
img.src = 'http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif';
jQuery("#gifimg").attr("src", img.src + '?s=' + d.getTime());
},32000);*/
});
</script>
But its not woking well.
Any help will be appreciate and waiting for right answer.
You can see this at here : Link
Upvotes: 0
Views: 335
Reputation: 931
Try to replace the src
then put the original again. Here is an example.
Run the snippet and let me know if this works for you.
I have used button to refresh the image, you can use as per your scenario.
function test1(){
jQuery('#myimg').attr('src','placeholder.png');
jQuery('#myimg').attr('src','http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif');
}
#myimg{
width:300px;
height:300px;
border:0px none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<button onclick="test1();">
refresh image
</button>
<img id="myimg" src="http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif" alt="dgfdgdf gfd gdfg fdsg dfs gdfsgdfsgdfg" />
Upvotes: 1
Reputation: 1794
You need to use setInterval instead of setTimeout
function func() {
var d = new Date();
var img = new Image();
img.src = 'http://www.goldenswange.com/wp-content/uploads/2016/05/stoptyre.gif';
jQuery("#gifimg").attr("src", img.src + '?s=' + d.getTime());
}
var timer = setInterval(func, 30000);
Upvotes: 0