我试图显示相同的图像,这是一个gif(动画)和jpeg。我每隔几秒钟就会更换一次src。
我在dev工具中看到src已经改变,但是gif没有动画效果。
setInterval(function(){
if(c == 1){
imgExt = 'assets/images/resize.gif'
++c;
}
else{
imgExt = 'assets/images/resize.jpg';
--c;
}
// document.querySelector('#floorImgId').src = imgExt;
$('#floorImgId').attr('src', imgExt);
}, 3000)`当我检查元素时,它正在改变,但在页面中,gif不播放。我做错了什么?
发布于 2020-01-11 13:35:16
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<img id="floorImgId" src="https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Hamiltonian_path.svg/440px-Hamiltonian_path.svg.png" />
<script>
var c = 1,imgExt = "";
setInterval(function(){
if(c == 1){
imgExt = 'https://upload.wikimedia.org/wikipedia/commons/thumb/6/60/Hamiltonian_path.svg/440px-Hamiltonian_path.svg.png'
++c;
}
else{
imgExt = 'https://buffer.com/library/wp-content/uploads/2016/06/giphy.gif';
--c;
}
$('#floorImgId').attr('src', imgExt);
}, 3000);
</script>
</body>
</html>
https://stackoverflow.com/questions/59691837
复制相似问题