css - 背景视频无法在手机上播放?

标签 css html forms video mobile

我制作了一个着陆页,其中视频在表单的背景中播放。
它在台式机上运行良好,但我使用 Chrome 在我的 Android 设备上进行了检查,背景视频无法在其上播放。

谁能帮我解决这个问题。

这是我的 fiddle 的链接.

HTML:

   <p>
<video autoplay="" id="video" loop=""><source src="http://www.mygreencity.in/Enquiry.mp4" type="video/webm" /> <source src="Enquiry.mp4" type="video/mp4" /></video>
</p>  

<form action="" class="form" method="post">


<p><input name="enq_name" placeholder="Full Name" required="" type="text" autocomplete="off" alt="Full Name" title="Full Name"/></p>

<p><input name="enq_mobile" placeholder="Mobile Number" required="" type="number" autocomplete="off" alt="Number" title="Number"/></p>

<p><input name="enq_email" placeholder="Email" required="" type="email" autocomplete="off" alt="Email ID" title="Email ID"/></p>
<input class="button button-block" name="enq_submit" type="submit" value="Go To Site" alt="Go To Site" title="Go To Site"/></form>

CSS:

    *, *:before, *:after {
  box-sizing: border-box;
}

html {
  overflow-y: scroll;
}

body {
  background: #fff;
  font-family: 'Titillium Web', sans-serif;
}

a {
  text-decoration: none;
  color: #1ab188;
  -webkit-transition: .5s ease;
          transition: .5s ease;
}
a:hover {
  color: #179b77;
}

.form {
  background: rgba(19, 35, 47, 0.9);
  padding: 40px;
  max-width: 600px;
  margin: 80px auto;

  border-radius: 4px;
  box-shadow: 0 4px 10px 4px rgba(19, 35, 47, 0.3);
}


h1 {
  text-align: center;
  color: #ffffff;
  font-weight: 300;
  margin: 0 0 40px;
}

label {
  position: absolute;
  -webkit-transform: translateY(6px);
      -ms-transform: translateY(6px);
          transform: translateY(6px);
  left: 13px;
  color: rgba(255, 255, 255, 0.5);
  -webkit-transition: all 0.25s ease;
          transition: all 0.25s ease;
  -webkit-backface-visibility: hidden;
  pointer-events: none;
  font-size: 22px;
}

input, textarea {

  font-size: 22px;
  display: block;
  width: 100%;
  height: 100%;
  padding: 5px 10px;
  background: none;
  background-image: none;
  border: 1px solid #a0b3b0;
  color: #ffffff;
  border-radius: 0;
  -webkit-transition: border-color .25s ease, box-shadow .25s ease;
          transition: border-color .25s ease, box-shadow .25s ease;
}
input:focus, textarea:focus {
  outline: 0;
  border-color: #1ab188;
}

textarea {
  border: 2px solid #a0b3b0;
  resize: vertical;
}


.button {
  border: 0;
  outline: none;
  border-radius: 0;
  padding: 15px 0;
  font-size: 2rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  background: #1ab188;
  color: #ffffff;
  -webkit-transition: all 0.5s ease;
          transition: all 0.5s ease;
  -webkit-appearance: none;
}
.button:hover, .button:focus {
  background: #179b77;
}

.button-block {
  display: block;
  width: 100%;
}

.forgot {
  margin-top: -20px;
  text-align: right;
}

p {
margin-bottom: 40px;
}


video { 
    position: fixed;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    width: auto;
    height: auto;
    z-index: -100;
    transform: translateX(-50%) translateY(-50%);
  background: #fff;
  background-size: cover;
  transition: 1s opacity;
}

div{
margin:20px;
}

input[type=number]::-webkit-inner-spin-button, 
input[type=number]::-webkit-outer-spin-button { 
  -webkit-appearance: none; 
  margin: 0; 
}

input[type=number] {
-moz-appearance: textfield;
}

最佳答案

您的视频元素需要更多属性

<video autoplay loop muted playsinline id="video-background" poster="images/poster.jpg">

Safari 和移动版 Chrome 对移动视频的行为方式进行了更改。默认情况下,它只能在视频静音 时自动播放。但是对于 webkit/iOs 你还需要第二个属性; 在线播放。此属性使其可以内联播放,而不是跳转到全屏视频。

另外,如果您的目标是 iOS 11,请确保您的移动设备未在低功耗模式下运行。如果您使用的是 Android 版 Chrome,Data Saver 模式也会阻止自动播放,因此不会显示视频。无论如何都没有。

关于css - 背景视频无法在手机上播放?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31588115/

相关文章:

html - 检查弹出窗口是否正在关闭 Jquery Mobile

php - 通过表单向php发送json

html - CSS - 选择器 - 复选框和标签之间的额外内容

javascript - 有没有办法在 Chrome 中使用 HTML 来更改 Android 中的导航栏颜色?

javascript - jQuery - 向下滑动面板

html - 当我将尺寸减小到 480 像素时,我希望侧边栏向下移动,侧边栏内容使用媒体查询向上移动。?

php - MySQL 时间戳字段在表单提交时未更新

php - 如何限制表单的使用或限制访问

css - 哪里可以找到跨浏览器、CSS修改器?

html - div 的高度不会改变 CSS