简体   繁体   English

jQuery不适用于100vh的容器

[英]JQuery not working for container with 100vh

I'm trying to make my entire container( mainContainer , containing a 100vh full screen video and a text overlay) to the left using a click on a div class( next hvr-forward ) using jquery. 我试图通过使用jQuery在div类( next hvr-forward )上单击,使我的整个容器( mainContainer ,包含一个100vh的全屏视频和一个文本叠加层)在左侧。

https://jsfiddle.net/Lo7xto2t/6/ https://jsfiddle.net/Lo7xto2t/6/

$('.next').click(function() {$('.mainContainer').animate({"margin-right": '-=200'});});

Used the code above but its not working. 使用了上面的代码,但无法正常工作。 Have tested it with css:borders so it is not a jquery problem. 已经使用css:borders测试了它,所以这不是jquery的问题。

HTML: HTML:

<div class = "mainContainer">
    <video poster ="poster.png" autoplay loop>
        <source src ="images/video.mp4" type ="video/mp4">
        <source src ="video.webm" type ="video/webm">   
    </video>
    <div class = "overlayAll">
        <div class = "text"> 
            We are BLXCK Co.
        </div>
    </div>
</div>

CSS: CSS:

video {
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
min-width: 100%;
min-height: 100%;
width: auto;
height: auto;
z-index: 1;
background: transparent;
background-size: cover;
}
.mainContainer{
height: 100vh;
position: absolute;
opacity: 1;
}
.overlayAll {
z-index: 1;
position: absolute;
background: rgba(0,0,0,0.3);
top: 0;
bottom: 0;
left: 0;
right: 0;    
height: 120vh;
}
.text {
position: fixed;
max-width: 50vw;
min-width: 50vw;
top: 30vh;
bottom: 30vh;
left: 15vw;
color: white;
font-family: "HelveticaNeue-Bold", Helvetica, Arial, sans-serif;
font-size: 12vw;
display: flex;
line-height: 0.8em;
flex-direction: column;
justify-content: center;
align-items: center;
}

Also have used Inspector but it seems my mainContainer is not moving. 也使用过Inspector,但似乎我的mainContainer没动。 Are there any other ways to move the entire container to the left upon a mouse click like a slider? 还有其他方法可以将整个容器向左移动,就像单击滑块一样。

It would not animate because of the fixed property you gave to the video and .text elements. 由于您赋予了video.text元素fixed属性,因此无法设置动画。

Changing the mainContainer to relative and the sub elements to absolute (and some other small things, which you can see in the snippet), it works. 将mainContainer更改为relative ,将sub元素更改为absolute (以及一些其他小内容,您可以在代码段中看到),可以正常工作。

Hope it helps! 希望能帮助到你!

 $('.next').click(function() { $('.mainContainer').animate({ right: '+=100vw' }, 2000); }); 
 video { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); min-width: 100%; min-height: 100%; width: auto; height: auto; z-index: 1; background: transparent; background-size: cover; } .mainContainer{ height: 100vh; max-height: 100vh; max-width: 100vw; position: relative; opacity: 1; right: 0; overflow: hidden; } .overlayAll { z-index: 1; position: absolute; background: rgba(0,0,0,0.3); top: 0; bottom: 0; left: 0; right: 0; height: 100vh; } .text { position: absolute; max-width: 50vw; min-width: 50vw; top: 30vh; bottom: 30vh; left: 15vw; color: white; font-family: "HelveticaNeue-Bold", Helvetica, Arial, sans-serif; font-size: 12vw; display: flex; line-height: 0.8em; flex-direction: column; justify-content: center; align-items: center; } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class = "mainContainer"> <video poster ="poster.png" autoplay loop> <source src ="http://techslides.com/demos/sample-videos/small.mp4" type ="video/mp4"> <source src ="http://techslides.com/demos/sample-videos/small.webm" type ="video/webm"> </video> <div class = "overlayAll"> <div class = "text next"> We are BLXCK Co. </div> </div> </div> 

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

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