视频没有在safari中显示,但只在滚动后显示

时间:2016-11-25 12:34:59

标签: javascript jquery css

我有一个视频,在使用Safari时,没有按照应有的方式做出响应。它确实加载,因为我可以听到视频的声音,但我只能在滚动一下后看到视频。换句话说:直到我滚动浏览器窗口才能看到视频。 Please Check here然后点击一个红色的包。

这是我用过的代码:

id  type periodicity    execute_operation
1   1    3              TRUE
2   1    3              FALSE
3   1    3              FALSE
4   1    3              TRUE
5   1    3              FALSE
6   1    3              FALSE
7   1    3              TRUE
8   1    3              FALSE
9   1    3              FALSE
10  2    2              TRUE
11  2    2              FALSE
12  2    2              TRUE
13  2    2              FALSE
14  2    2              TRUE
15  2    2              FALSE
16  2    2              TRUE
$('#video-togglebutton').on('click', function() {
  var videoDiv = $('#videoDiv').toggle();

  if (videoDiv.is(':visible')) {
    $('#video').get(0).load();
    $('#video').get(0).play();
  } else {
    $('#video').get(0).pause();
  }
});

$(document).ready(function() {
  $('#video').on('ended', function() {
    $('#video').get(0).pause();
    $('#videoDiv').toggle();
  });
});
#videoDiv {
            display:none;
            left: 50%;
            transform: translate(-50%, 0);
            height: 35vw;
            position: relative;
            text-align:center;
            
          }
          
          #videoBlock{
            width:60vw;
            height: 35vw;
            position: absolute;
            top: 0;
            left: 0;
            left: 50%;
            transform: translate(-50%, 0);
            
          }
          
          .videoClick {
            text-align: center;
          }
          
          .videoClick a {
            color: white;
            font-size: 1.7em;
            cursor: pointer;
            cursor: hand
          }
          
          
          video {
            background-image: url("{{ 'fotel-photography-loading-3.svg' | url_asset }}");
            background-repeat: no-repeat;
            background-size: 100px 100px;
            background-position: center;
            margin-top:-34px;
            width:100%;           
}

现在我考虑了一个hack,在上面的if语句中使用下面的额外代码,但是我没有用。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="video-togglebutton">Toggle video</button>
<div id="videoDiv" style="display:none">
  <div id="videoBlock">
    <video preload="preload" id="video">
      <source src="https://static.webshopapp.com/shops/054833/files/093143183/fotel-photography-course-tour-workshop-video-4.mp4" type="video/mp4">
    </video>
  </div>
</div>

2 个答案:

答案 0 :(得分:0)

只需添加width: 100%视频元素#video即可获得与身体宽度相同的广告:

#video {
  width:100%;
}

$('#video-togglebutton').on('click', function() {
  var videoDiv = $('#videoDiv').toggle();

  if (videoDiv.is(':visible')) {
    $('#video').get(0).load();
    $('#video').get(0).play();
  } else {
    $('#video').get(0).pause();
  }
});

$(document).ready(function() {
  $('#video').on('ended', function() {
    $('#video').get(0).pause();
    $('#videoDiv').toggle();
  });
});
#videoDiv {
  width: 100%;
  height: 360px;
  position: relative;
}
#videoBlock,
#videoMessage {
  width: 100%;
  height: 360px;
  position: absolute;
  top: 0;
  left: 0;
}

#video {
  width:100%;
}

.videoClick {
  text-align: center
}
.videoClick a {
  color: white;
  background-color: rgba(241, 241, 241, 0.25);
  font-size: 1.7em;
  cursor: pointer;
  cursor: hand
}

video {
 background-image: url("{{ 'fotel-photography-loading-3.svg' | url_asset }}");
 background-repeat: no-repeat;
 background-size: 100px 100px;
 background-position: center;
 margin-top:-34px;
 width:100%;           
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button id="video-togglebutton">Toggle video</button>
<div id="videoDiv" style="display:none">
  <div id="videoBlock">
    <video preload="preload" id="video">
      <source src="https://static.webshopapp.com/shops/054833/files/093143183/fotel-photography-course-tour-workshop-video-4.mp4" type="video/mp4">
    </video>
  </div>
</div>

答案 1 :(得分:0)

这可行(有点黑客):

/*makes window scroll down and up again one pixel, after page is loaded*/  
$(window).load(function(){
   $(window).scrollTop($(window).scrollTop()+1);
   $(window).scrollTop($(window).scrollTop()-1); 
}