禁用GIF自动播放

Disable GIF autoplay

本文关键字:自动播放 GIF 禁用      更新时间:2023-09-26

我正在寻找一种方法来自动禁用自动播放的动画gif张贴在我的小聊天网站(基于php)我想我已经接近了,但是我对这个脚本完全没有想法:

<script>
myVid=document.getElementsByTagName('img');
function disableAutoplay()
  { 
  myVid.autoplay=false;
  myVid.load();
  } 
</script> 
</head>
<body onload="disableAutoplay();"> 

目的:防止发布的GIF(动画)自动开始加载。由于

能够使它与jquery工作,但->试图找出一种更干净的方法来做到这一点,关于鼠标事件的建议让我思考,也许这样的事情是可能的?

        $com  = $_POST['txt'];
        $count = strlen($com);
        $com = stripslashes($com);
        $alter1 = array(".gif");
        $com = str_ireplace($alter1, ".gif autoplay=false onmouseover **MAKE IT PLAY**", $com);

我现在如履薄冰,甚至不确定它是否可能控制gif这样的html标签

我不知道是否有本地的停止方式,但你能做的就是把静态png/jpeg图片这是你的gif图片的起点。然后当你点击播放时,将静态图像替换为gif动画。

更新:

<script>
window.document.onload = function(e){ 
   var myVid=document.getElementsByTagName('img');
   var gifPath=myVid.src;
   myVid.src='/static/image/path.png'; 
   // now you can use your gif depending on business logic
}    
</script>

PS:代码没有测试…这只是为了显示一个伪代码。