I tried to make parallax text and could not. The code seems harmless and doesn't seem to do anything bad, but the scrolling looks and feels completely wrong.
The markup is as follows:
<section class="section-parallax">
<div class="container text-center">
<div class="flex-row-columns">
<div class="flex-row">
<h2 class="heading flex-8">
<span class="heading-sub">Some Header</span>
<span class="heading-bottom">getting also long<sup>
</h2>
</div>
</div>
</div>
</section>
Styles:
.container {
box-sizing: border-box;
margin-left: auto;
margin-right: auto;
padding-left: 15px;
padding-right: 15px;
width: 1400px;
}
.text-center {
text-align: center;
}
.section-parallax {
background: black;
overflow: hidden;
&,
& .container,
& .flex-row {
min-height: 545px;
}
& .container {
transform: translate3d(0, -100%, 0);
}
}
.flex-row-columns {
display: flex;
flex-direction: column;
margin-top: 0;
margin-bottom: 0;
margin-left: 0;
margin-right: 0;
}
.flex-row {
align-items: center;
display: flex;
justify-content: center;
margin-left: -15px;
margin-right: -15px;
}
.flex-8 {
flex-basis: 66.66666666666667%;
padding-left: 15px;
padding-right: 15px;
}
.heading {
color: white;
font-size: 54px;
letter-spacing: .66px;
line-height: 1.273em;
}
.heading-sub {
display: block;
margin-bottom: 20px;
}
And finally, the JS I used is as follows:
class ParallaxSection {
constructor() {
this.el = document.querySelector('.section-parallax');
this.els = {
container: this.el.querySelector('.container')
};
this.calcBounds();
window.addEventListener('scroll', this.onScroll.bind(this));
window.addEventListener('resize', () => {
this.calcBounds();
this.onScroll();
});
}
calcBounds() {
if (this.tween) {
this.tween.kill();
this.els.container.removeAttribute('style');
}
const rect = this.el.getBoundingClientRect();
const scrollY = ParallaxSection.getScroll();
this.start = (rect.top + scrollY) - (window.innerHeight * 0.75);
this.end = this.start + this.el.offsetHeight + window.innerHeight;
this.tween = TweenLite.fromTo(this.els.container, 1, {
css: {
force3D: true,
y: -this.el.offsetHeight
}
}, {
paused: true,
css: {
force3D: true,
y: this.end - this.start - this.el.offsetHeight
},
ease: Linear.easeNone
});
}
onScroll() {
const scroll = ParallaxSection.getScroll();
if (scroll >= this.start && scroll <= this.end) {
const diff = this.end - this.start;
const offset = scroll - this.start;
const perc = offset / diff;
this.tween.progress(perc);
}
}
static getScroll() {
return window.pageYOffset || document.documentElement.scrollTop;
}
}
const p = new ParallaxSection();
Now, itβs strange that, trying to detect the problem, I put it in Pen to try to understand where this happened, and everything seemed to be in order in the pen. This made me delete all the elements on my page and accurately reproduce the pen, it turns out that for some unknown reason, the effect is perfect in the codefen and leaves it.
I downloaded all the HTML that the codefile generates, and it experiences the same experience.

Pen is here to see him.
What is wrong with him?