Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
228 views
in Technique[技术] by (71.8m points)

javascript - Safari 14 flickers video on display:none/display block toggle

I have noticed that on Safari 14, there is a strange issue with the video tag. When a video is being streamed and the corresponding parent container set "display" to "none," it creates a small noticeable flicker with reproduce rate of 3/10 times.

On Chrome/Firefox/Edge, old versions of Safari, the flicker does not occur.

I also have noticed, when there is a complex DOM tree, it flickers more often.

Any suggestions of what might causing it and how I can fix it?

Here is an example Codepen

<div id="container">
 <video width="640" muted="true" height="360" controls="" autoplay="true" id="videoTag" loop="true">
    <source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148422/Vienna-SD.mp4" type="video/mp4">
</video>
   <video width="640" muted="true" height="360" controls="" 
          loop="true" autoplay="true" id="videoTag">
    <source src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/148422/Vienna-SD.mp4" type="video/mp4">
</video>
  
  <span>Foo string</span>
</div>

<button id="test">Hide me</button>
<button id="show"> Show me </button>

 <script>
 const videoTag = document.querySelector('#videoTag');
 const container = document.querySelector('#container');
 const button = document.querySelector('#test');
 const show = document.querySelector('#show');

 button.onclick = function(){
   container.style.display = 'none';
 };

 show.onclick = function(){
   container.style.display = 'block';
 };
 </script>
question from:https://stackoverflow.com/questions/65922251/safari-14-flickers-video-on-displaynone-display-block-toggle

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...