Heim  >  Fragen und Antworten  >  Hauptteil

Passen Sie die Videoanzeige automatisch an die Mediengröße an

<p>Ich habe vor, ein Hintergrundvideo auf einer Webseite abzuspielen und habe unterschiedliche Videodateien für Mobilgeräte und Desktops. I</p> <pre class="brush:php;toolbar:false;"><video autoplay loop muted playinginline> <source src="desktop.mp4" type="video/mp4"> <source src="desktop.webm" type="video/webm"> <img src="fallback.jpg" > </video></pre> <p>Ich habe eine Lösung für Medienabfragen gesehen, aber soweit ich weiß, liegt sie außerhalb der Spezifikation und wird von iOS/Safari nicht unterstützt. </p>
P粉807239416P粉807239416421 Tage vor494

Antworte allen(1)Ich werde antworten

  • P粉256487077

    P粉2564870772023-08-26 09:36:35

    您可以使用媒体查询根据其定义使用src或其他内容。在CSS-Tricks上查看此文章:https://css-tricks.com/video-source-by-screen-size/ 但是,看起来这在所有浏览器上都不是一个稳定的功能。

    <video controls> 
       <source src="video-small.mp4" type="video/mp4" media="all and (max-width: 480px)"> 
       <source src="video-small.webm" type="video/webm" media="all and (max-width: 480px)"> 
       <source src="video.mp4" type="video/mp4"> 
       <source src="video.webm" type="video/webm"> 
    </video>

    如文章所述,另一种方法是根据视口大小使用JavaScript更改视频的src。

    Antwort
    0
  • StornierenAntwort