2017-01-23 75 views
2

我對jQuery相當陌生,但真的很喜歡它可以做的事情,我正在取得不錯的進展,但是當我按下play時,我無法實現打開div。 我不想在此項目中使用Bootstrap模式。我想要的是以視口寬度和高度的全寬和高度打開視頻。 目前不播放,這是我的codepen,我的代碼如下。在不使用引導程序的情況下創建全屏視頻覆蓋

作爲一個例子,我想實現類似this,當按下播放。

$(document).ready(function(){ 
    $(".glyphicon-play-circle").click(function(){ 
     $(".movie").css("display","block") 
    }) 
}) 

CSS

.movie{ 
    display:none; 
    position:absolute; 
    z-index:1; 
    top:0; 
    width:100%; 
    height:100vh; 
    background:black; 

}

回答

1

我已經做了更改您的密碼。我禁用了全屏內容,因爲它足夠滿足一個視頻。不需要額外的視頻,它使它工作。

$(document).ready(function() { 
 
    $(".glyphicon-play-circle").click(function() { 
 
     $(".movie").css("display", "block") 
 
     $("#bgvid").toggleClass("is-not-active"); 
 
     $(".fullscreen").toggleClass("is-video-active"); 
 
     $(".fullscreen.is-video-active").prop("autoplay", true); 
 
    }); 
 
});
* { 
 
    box-sizing: border-box; 
 
    ; 
 
} 
 

 
body, 
 
html { 
 
    height: 100%; 
 
} 
 

 
.logo { 
 
    float: left; 
 
    width: 50%; 
 
} 
 

 
.glyphicon { 
 
    font-size: 3em; 
 
    text-align: center; 
 
} 
 

 
.header { 
 
    position: relative; 
 
    z-index: 1; 
 
} 
 

 
nav { 
 
    float: right; 
 
    width: 50%; 
 
} 
 

 
nav ul { 
 
    list-style: none; 
 
} 
 

 
nav li { 
 
    float: left; 
 
    padding: 15px 
 
} 
 

 
nav li a { 
 
    display: block; 
 
    color: #000; 
 
    margin-top: 1em; 
 
} 
 

 
.centered { 
 
    position: relative; 
 
    top: 50%; 
 
    z-index: 1; 
 
    color: #fff; 
 
    text-shadow: 1px 1px 10px #000; 
 
} 
 

 
.content { 
 
    /*position: relative;*/ 
 
} 
 

 
video { 
 
    background-size: cover; 
 
    width: 100%; 
 
    position: absolute; 
 
    height: auto; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: -1; 
 
    object-fit: contain; 
 
} 
 

 

 
.movie { 
 
    display: none; 
 
    position: absolute; 
 
    z-index: 1; 
 
    top: 0; 
 
    width: 100%; 
 
    height: 100vh; 
 
    background: black; 
 
} 
 
.is-not-active { display: none;} 
 
.fullscreen { display: none; } 
 
.fullscreen.is-video-active { 
 
    position: fixed; 
 
    left: 0; 
 
    top: 0; 
 
    width: 0; 
 
    right: 0; 
 
    height: 100%; 
 
    width: 100%; 
 
    z-index: 9999; 
 
    background: #000; 
 
    display: block; 
 
} 
 

 
.is-video-active video { 
 
    right: 0; 
 
    width: auto; 
 
    height: 100%; 
 
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/> 
 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<body> 
 
     <section class="header container"> 
 
     <div class="logo"> 
 
      <img src="https://dummyimage.com/150" alt=""> 
 
     </div> 
 
     <nav> 
 
      <ul> 
 
       <li><a href="">Home</a></li> 
 
       <li><a href="">About</a></li> 
 
       <li><a href="">Teach</a></li> 
 
       <li><a href="">Contact us</a></li> 
 
      </ul> 
 
     </nav> 
 
    </section> 
 
    <section class="content"> 
 
     <div class="container-fluid"> 
 
      <div class="centered"> 
 
       <h1 class="text-center">We Evolve with our students</h1> 
 
       <a href="#"> 
 
        <span class="glyphicon glyphicon-play-circle"></span> 
 
        <a/> 
 
      </div> 
 
     </div> 
 
     <video poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg" id="bgvid" playsinline autoplay muted loop> 
 
      <!-- WCAG general accessibility recommendation is that media such as background video play through only once. Loop turned on for the purposes of illustration; if removed, the end of the video will fade in the same way created by pressing the "Pause" button --> 
 
      <source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm"> 
 
      <source src="http://thenewcode.com/assets/videos/polina.mp4" type="video/mp4"> 
 
     </video> 
 
     <div class="container"> 
 
      <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> 
 
       <div class="panel panel-default"> 
 
        <div class="panel-heading" role="tab" id="headingOne"> 
 
         <h4 class="panel-title"> 
 
     <a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="true" aria-controls="collapseOne"> 
 
      Collapsible Group Item #1 
 
     </a> 
 
       </h4> 
 
        </div> 
 
        <div id="collapseOne" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="headingOne"> 
 
         <div class="panel-body"> 
 
          Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
         </div> 
 
        </div> 
 
       </div> 
 
       <div class="panel panel-default"> 
 
        <div class="panel-heading" role="tab" id="headingTwo"> 
 
         <h4 class="panel-title"> 
 
     <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> 
 
      Collapsible Group Item #2 
 
     </a> 
 
     </h4> 
 
        </div> 
 
        <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> 
 
         <div class="panel-body"> 
 
          Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
         </div> 
 
        </div> 
 
       </div> 
 
       <div class="panel panel-default"> 
 
        <div class="panel-heading" role="tab" id="headingThree"> 
 
         <h4 class="panel-title"> 
 
     <a class="collapsed" role="button" data-toggle="collapse" data-parent="#accordion" href="#collapseThree" aria-expanded="false" aria-controls="collapseThree"> 
 
      Collapsible Group Item #3 
 
     </a> 
 
     </h4> 
 
        </div> 
 
        <div id="collapseThree" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingThree"> 
 
         <div class="panel-body"> 
 
          Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS. 
 
         </div> 
 
        </div> 
 
       </div> 
 
      </div> 
 
     </div> 
 
    </section> 
 
    <section class="fullscreen"> 
 
     <video poster="https://s3-us-west-2.amazonaws.com/s.cdpn.io/4273/polina.jpg" id="bgvid" playsinline muted loop> 
 
      <!-- WCAG general accessibility recommendation is that media such as background video play through only once. Loop turned on for the purposes of illustration; if removed, the end of the video will fade in the same way created by pressing the "Pause" button --> 
 
      <source src="http://thenewcode.com/assets/videos/polina.webm" type="video/webm"> 
 
      <source src="http://thenewcode.com/assets/videos/polina.mp4" type="video/mp4" style="display: none;"> 
 
     </video> 
 
    </section> 
 
</body>

+0

謝謝!我仍然試圖理解它,我想要一個視頻作爲預告片,當你點擊它時,它會運行其他電影,因爲我支付了兩部電影。它不會起作用嗎? – Nofel

+0

@Nofel你想運行預告片上的全屏div點擊嗎? –

+0

是的,通過電影我的意思是有聲廣告,其中預告片僅僅是幾秒鐘而靜音。 – Nofel

相關問題