JSFiddle - React, Tailwind, and code Playground
by Alexandru Gatea
HTML
<div id="vs-section" class="vs-section">
<div class="first"></div>
<div class="second"></div>
<div class="third"></div>
<div class="fourth"></div>
<div class="fifth"></div>
<div class="sixth"></div>
</div>
SCSS
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.vs-section {
div {
height: 100vh;
}
.first {
background: #ffcb11;
}
.second {
background: #ff3411;
}
.third {
background: #ffcb11;
}
.fourth {
background: #ff1211;
}
.fifth {
background: #ffee11;
}
.sixth {
background-color: #ffca11;
background-image: url(https://assets.website-files.com/5ce7d8a34a11c3cc57face08/5d26f04b1443e06ec1cc54a6_globe.png);
background-size: cover;
background-attachment: fixed;
background-position: 100% 100%;
}
}
JavaScript
var scroll=new SmoothScroll(document,30,15);
function SmoothScroll(target, speed, smooth) {
if (target === document)
target = (document.scrollingElement
|| document.documentElement
|| document.body.parentNode
|| document.body) // cross browser support for document scrolling
var moving = false
var pos = target.scrollTop
var frame = target === document.body
&& document.documentElement
? document.documentElement
: target // safari is the new IE
target.addEventListener('mousewheel', scrolled, { passive: false })
target.addEventListener('DOMMouseScroll', scrolled, { passive: false })
function scrolled(e) {
e.preventDefault(); // disable default scrolling
var delta = normalizeWheelDelta(e)
pos += -delta * speed
pos = Math.max(0, Math.min(pos, target.scrollHeight - frame.clientHeight)) // limit scrolling
if (!moving) update()
}
function normalizeWheelDelta(e){
if(e.detail){
if(e.wheelDelta)
return e.wheelDelta/e.detail/40 * (e.detail>0 ? 1 : -1) // Opera
else
return -e.detail/3 // Firefox
}else
return e.wheelDelta/120 // IE,Safari,Chrome
}
function update() {
moving = true
var delta = (pos - target.scrollTop) / smooth
target.scrollTop += delta
if (Math.abs(delta) > 0.5)
requestFrame(update)
else
moving = false
}
var requestFrame = function() { // requestAnimationFrame cross browser
return (
window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
window.oRequestAnimationFrame ||
window.msRequestAnimationFrame ||
function(func) {
window.setTimeout(func, 1000 / 50);
}
);
}()
}