简体   繁体   English

使用 PHP 内联 Styles 添加视频背景

[英]Add Video Background Using PHP Inline Styles

Is there a way to swap out the image URL and replace it with a video file for use as a background video instead of image?有没有办法换出图像 URL 并将其替换为视频文件以用作背景视频而不是图像?

Here's the code for my background image i want to convert to a background video:这是我要转换为背景视频的背景图像的代码:

echo '<style type="text/css" media="screen">
        body.front-page {
            background-image: url(' . esc_html( $image ) . ');
</style>';

I need to apply the video to this body.front-page class and not sure what the best method is however i would prefer using PHP.我需要将视频应用到这个 body.front-page class 并且不确定最好的方法是什么,但是我更喜欢使用 PHP。

First you should place a video like this:首先,您应该放置这样的视频:

<video autoplay muted loop id="myVideo">
  <source src="rain.mp4" type="video/mp4">
</video>

Then add some CSS to send it background:然后添加一些 CSS 来发送它的背景:

#myVideo {
  position: fixed;
  right: 0;
  bottom: 0;
  min-width: 100%;
  min-height: 100%;
} 

Working example: https://www.w3schools.com/howto/howto_css_fullscreen_video.asp工作示例: https://www.w3schools.com/howto/howto_css_fullscreen_video.asp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM