Parallax effect - make section appear behind previous section without moving content - html

So what I currently have is a parallax effect that works fine, but I can't figure out how to make one section "slide up" and reveal the next section, making it look like a smooth section transition. Currently my content on the second section just keeps scrolling down until it's in its place, and I can't seem to make it appear behind the first section. I currently have this: https://jsfiddle.net/165pw4ks/3/.
index.html:
<div class="parallax-wrapper">
<div class="frame-top"></div>
<section class="parallax-section part1">
<div class="frame-bottom"></div>
<div class="part1-sticky-container">
<div class="part1-sticky">
</div>
</div>
</section>
<section class="parallax-section part2">
<div class="part2-content">
<h1 class="part2-text">
Some text here
</h1>
</div>
</section>
</div>
style.css:
body {
margin: 0;
}
.parallax-wrapper {
top: 100vh;
}
.parallax-section {
position: relative;
}
.part1 {
background: url("https://place-hold.it/1920x1080") no-repeat;
width: 100vw;
height: 100vh;
background-size: cover;
z-index: 4;
}
.frame-bottom {
position: sticky;
z-index: 100;
top: calc(100vh - 40px);
height: 40px;
width: 100%;
background-color: #111;
}
.part2 {
margin: 0;
background: url("https://place-hold.it/1920x1080") no-repeat;
background-size: 100vw;
width: 100vw;
height: 100vh;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
z-index: 1;
}
.part2-content {
position: sticky;
width: 30rem;
height: 5rem;
z-index: 1;
background-attachment: scroll;
background-color: transparent;
margin-left: calc(50% - 15rem);
top: calc(50% - 2.5rem);
}
.part2-text {
margin: 0;
color: white;
font-size: 32px;
text-align: center;
}
What I am attempting to make is something like on this picture:
Any help would be appreciated.

Related

Transparent overlay div layer breaking out of parent container?

Trying to build out a hero style masthead with a transparent cover image, and a color tint overlay; then display some text on top of this. I am using bootstrap 3 as underlying framework.
I have my hero wrapped in a div, I then have two child div. One contains the background tint layer, the other contains the text/title.
The background div layer is breaking out of the parent wrapper div and covering the entire viewport below it. I'm not sure where i went wrong.
Fiddle of my broken attempt:
Fiddle
#page-title {
font-size: 2.2em;
padding: 20px 40px;
margin-bottom: 40px;
}
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
.bg-wrapper {
background-image: url(/whatever.png);
background-position: right center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: scroll;
}
<div class="bg-wrapper">
<div class="bg-layer"></div>
<header id="page-title">
<div class="container">
About Us </div>
</header>
</div>
Add high z-index on .bg-layer, beacuse bootstrap CSS navbar Class default z-index is 1000
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
z-index:1001;;
}
https://jsfiddle.net/lalji1051/9b46x5yo/3/
All your code is absolutely fine, Just add this line position: relative;to the .bg-wraper class and you will get the desired result!
#page-title {
font-size: 2.2em;
padding: 20px 40px;
margin-bottom: 40px;
}
.bg-layer {
opacity: 0.75;
background-color: #f7f8fa;
background-color: #f005; /* just adding this for visibility*/
position: absolute;
height: 100%;
width: 100%;
top: 0;
left: 0;
}
.bg-wrapper {
background-image: url(/whatever.png);
background-position: right center;
background-size: cover;
background-repeat: no-repeat;
background-attachment: scroll;
/*Just this additionale property*/
position: relative;
}
<div class="bg-wrapper">
<div class="bg-layer"></div>
<header id="page-title">
<div class="container">
About Us </div>
</header>
</div>

The fixed video with a lower z-index than my main container shows shortly when page loads

I've two sections. One section is over the other, with a z-index of 1.
The problem however is that on page load / refresh the section under the other section shows for a short second.
I've tried changing the position of my CSS in the head so this would load first. I've even put the z-index line on the very top of the CSS file.
<section class="full-grid" id="section-1"></section>
<div id="trigger" class="fixer"></div>
<section class="full-grid" id="section-1"></section>
#section-1 {
z-index: 1;
max-width: 100vw;
overflow: hidden;
height: 100vh;
background-image: url("img/page-1");
background-repeat: no-repeat;
background-size: cover;
position: absolute;
top: 0vh;
}
.fixer {
height: 100vh;
width: 100vw;
position: relative;
top: 100vh;
}
#section-2 {
max-width: 100vw;
overflow: hidden;
height: 100vh;
background-repeat: no-repeat;
background-size: cover;
position: fixed;
top: 0;
}
I expected the element not to flicker on load. But it does flicker on load.
You have a typo in your HTML markup. Both sections have an id of section-1.
The reason for the flicker could be because you are loading an image in as the background for section 1, so until this is loaded you will see the other section briefly behind it. Try setting a background colour on section 1 to white or what ever the background colour of the page is.
In the snippet below I have demonstrated this with 2 images section 1 has a cat and section 2 has a dog. You should only ever see the cat when loaded.
#section-1 {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
background-color: #fff;
background-image: url("https://source.unsplash.com/featured/?cat");
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
}
.fixer {
height: 100%;
width: 100%;
position: relative;
top: 100vh;
}
#section-2 {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 0;
overflow: hidden;
background-image: url("https://source.unsplash.com/featured/?dog");
background-repeat: no-repeat;
background-size: cover;
}
<section class="full-grid" id="section-1"></section>
<div id="trigger" class="fixer"></div>
<section class="full-grid" id="section-2"></section>
If you don't mind using JS, you can bring section 2 as invisible, and then, when DOM is loaded, set it back to visible, like this:
<section class="full-grid" id="section-1"></section>
<div id="trigger" class="fixer"></div>
<--! i changed the id of this element, i guess it should be section-2. Added a class hidden too-->
<section class="full-grid hidden" id="section-2"></section>
<script>
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', show_sections);
} else {
show_sections();
}
function show_sections() {
var section2 = document.querySelector('#section2');
//remove class hidden from section 2 when DOM is loaded to make it become visible and avoid flicking
//if you intend to bring both elements together, just do the same for section1 (add class=hidden and declare it here with the same logic.
section2.className = section2.className.replace(/hidden/g, '');
}
</script>
#section-2.hidden {
display:none;
}
#section-1 {
z-index: 1;
max-width: 100vw;
overflow: hidden;
height: 100vh;
background-image: url("img/page-1");
background-repeat: no-repeat;
background-size: cover;
position: absolute;
top: 0vh;
}
.fixer {
height: 100vh;
width: 100vw;
position: relative;
top: 100vh;
}
#section-2 {
max-width: 100vw;
overflow: hidden;
height: 100vh;
background-repeat: no-repeat;
background-size: cover;
position: fixed;
top: 0;
}

How to stop overscroll in Safari in this case?

I have a website-slider where every section has height of 100vh. So each section is a slide. At the bottom of the website I need to have a simple footer. It works fine in all browsers but in Safari it kind of jumps because of overscroll.
Link to example
Gray div is an image which is outside my slider and is kind of behind all of the slides beacuse I need to change it's opacity on scroll. My footer is outside of slider as well.
<div class="section1">SECTION 1</div>
<div class="section2">SECTION 2</div>
<div class="section3">
SECTION 3
</div>
<div class="bg" style="background: gray"></div>
<footer>FOOTER HERE</footer>
CSS
* {
margin: 0;
padding: 0;
}
.section3,
.section2,
.section1 {
width: 100vw;
height: 100vh;
overflow: hidden;
position: relative;
z-index: 2;
background: #000;
color: white;
margin-top: 15%;
}
.section3 {
background: transparent;
margin-top: 0;
z-index: 10;
}
.bg {
position: fixed;
top: 0;
left: 0;
width: 100vw;
height: 100vh;
background-image: linear-gradient(rgba(0, 0, 0, .5), rgba(0, 0, 0, .5)), url(bf34577….png);
background-repeat: no-repeat;
background-size: cover;
}
footer {
display: flex;
position: absolute;
-webkit-align-items: center;
-ms-flex-align: center;
align-items: center;
padding: 0 10px;
z-index: 9;
width: 100vw;
height: 65px;
object-fit: cover;
background: #000;
color: #727272;
}
So when overscroll is happening footer jumps up and behind it you can see an image which shouldn't happen.
It can be fixed if I give footer position: fixed and bottom: 0 but I don't need it to be position: fixed, I just need it to be at the bottom of the page.

Fixed div top of web page broken result

I have a fixed header with a full screen background image under that my sections. what i am trying to do is if i have a alert it will echo above the whole page pushing down the header and hero. but it either wont show up or when i do get it to show it wont stay fixed and scrolls with the page.
.sitrep {
top 0;
height: 50px;
width: 100%;
position: fixed;
z-index: 10000;
}
.siteHeader {
min-height: 76px;
height: 76px;
overflow: visible;
background-color: #000;
color: #f4f4f4;
position: fixed;
top: 0;
z-index: 10000;
}
#hero {
height: 100vh;
}
.hero {
background: url(images/hero-bg.jpg) no-repeat top center;
background-color: #000;
background-size: cover;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
}
#hero-content {
position: absolute;
width: 100%;
bottom: 0%;
}
#hero-content a {
background-color: #131313;
padding-top: 10px;
height: 40px;
display: block;
font-size: 12px;
text-align: center;
text-transform: uppercase;
text-decoration: none;
}
#hero-content img {
display: block;
margin-top: 2px;
max-height: 145px;
margin-right: auto;
margin-left: auto;
margin-bottom: 53px;
padding: 5px;
}
<div class="sitrep">
<div class="alert-status">
<div class="info">
<span class="closebtn" onclick="this.parentElement.style.display='none';">×</span>
<strong>Announcement!</strong> anouncment goes here.
</div>
</div>
</div>
<div id="siteHeader">my header</div>
<!-- Hero Unit -->
<div id="hero" class="hero">
<div id="hero-content">
<img src="content/images/logo-dt.png" class="img-responsive">
<a class="button" role="button" href="#base">Learn more</a>
</div>
</div>
You are mixing up classes and ID's.
In your HTML, you give the element the ID of sitrep, whereas you are giving the styles to the elements with the class of siterep.
Try either of the following options and you'll be set :
Changing the element attribute: <div id="sitrep"> to <div class="sitrep">
Changing the CSS to fit the proper elements: .sitrep { to #sitrep {
Happy coding !

Fixing an image to a fullscreen div

my question is simple.
I have this page: http://vacanor.com/tests/lared
There is that image in the middle of the first section that floats on the screen. I want to stick that image in the first section preservating its position whenever I change the screen size. I've tryed everything but I can't.
Here is a video about what is bothering me: https://www.youtube.com/watch?v=U37_1cY8nAs
My html(including second section):
<div class="container-a">
<!--<div class="col-lg-12">-->
<div class="img-cover">
<center><img class="img-cover-i floating" src="img/logo-background.png" alt="Logo">
</center>
</div>
</div>
<!--</div>-->
<!-- Presentación -->
<div class="container-b">
<!-- <div class="col-lg-12">-->
<div class="ani">
<div class="intro">
<h1 class="animated fadeInDown animated-d-1 cd-headline slide">
Bienvenido a La Red
<small>
<span class="text-primary cd-words-wrapper" style="width: 207px;">
<b class="is-hidden">Construir </b>
<b class="is-hidden">Jugar</b>
<b class="is-hidden">Sobrevivir</b>
<b class="is-visible">Divertir-se </b>
</span>
<span>nunca será lo mismo.</span>
</small>
</h1>
</div>
</div>
</div>
And my css:
.img-cover {
margin: 0 auto;
width: 95%;
position: relative;
z-index: 10;
margin-top: 50px;
}
.img-cover-i {
position: relative;
}
.container-a {
margin: 0 auto;
width: 100%;
height: 100%;
position: absolute;
top: 0;
z-index: -2;
background-image: url('../img/cover-background.jpg');
background-position: center;
background-repeat: none;
background-size: cover;
}
.container-b {
margin: 0 auto;
position: absolute;
width: 100%;
height: 100%;
z-index: -3;
top:100%;
}
I did not really understand your question, so here are 3 fixes to how I understood it.
.container-a {
margin: 0 auto;
width: 100%;
height: 100%;
position: absolute;
top: 0;
z-index: -2;
background-image: url('../img/cover-background.jpg');
background-position: center;
background-repeat: none;
background-size: cover;
overflow:hidden;
}
The above code should make your image not get out of the div when resizing the screen, and below is an example of how to resize the image accordingly;
.img-cover-i {
position: relative;
height:calc(100% - 50px)
}
Also, if you want your Logo to follow the screen but not be visible outside the container a, use this code:
.img-cover-i {
margin-left:calc(50% - 237px);
position: fixed;
}
.container-a {
margin: 0 auto;
width: 100%;
height: 100%;
position: absolute;
top: 0;
z-index: -2;
background-image: url('../img/cover-background.jpg');
background-position: center;
background-repeat: none;
background-size: cover;
overflow:hidden;
-webkit-backface-visibility: hidden;
-moz-backface-visibility: hidden;
backface-visibility: hidden;
}
Also, if using this code, remove the that wraps the img in the html part.
I hope this helped.