JQuery+JavaScript Full page parallax
페이지 정보
- 작성자인군
- 조회 : 189
- 작성일 : 2022-10-06 12:54
본문
Full page parallax
<style>
@import url(https://fonts.googleapis.com/css?family=Indie+Flower);
html, body {
overflow: hidden;
}
.background {
background-size: cover;
background-repeat: no-repeat;
background-position: center center;
overflow: hidden;
will-change: transform;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
height: 130vh;
position: fixed;
width: 100%;
-webkit-transform: translateY(30vh);
-ms-transform: translateY(30vh);
transform: translateY(30vh);
-webkit-transition: all 1.2s cubic-bezier(0.22, 0.44, 0, 1);
transition: all 1.2s cubic-bezier(0.22, 0.44, 0, 1);
}
.background:before {
content: "";
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: rgba(0, 0, 0, 0.3);
}
.background:first-child {
background-image: url(https://i.imgur.com/2tQoKAI.jpg);
-webkit-transform: translateY(-15vh);
-ms-transform: translateY(-15vh);
transform: translateY(-15vh);
}
.background:first-child .content-wrapper {
-webkit-transform: translateY(15vh);
-ms-transform: translateY(15vh);
transform: translateY(15vh);
}
.background:nth-child(2) {
background-image: url(https://i.imgur.com/Yl0v8sU.jpg);
}
.background:nth-child(3) {
background-image: url(https://i.imgur.com/ZzAc6qY.jpg);
}
/* Set stacking context of slides */
.background:nth-child(1) {
z-index: 3;
}
.background:nth-child(2) {
z-index: 2;
}
.background:nth-child(3) {
z-index: 1;
}
.content-wrapper {
height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-webkit-justify-content: center;
-ms-flex-pack: center;
justify-content: center;
text-align: center;
-webkit-flex-flow: column nowrap;
-ms-flex-flow: column nowrap;
flex-flow: column nowrap;
color: #fff;
font-family: Montserrat;
text-transform: uppercase;
-webkit-transform: translateY(40vh);
-ms-transform: translateY(40vh);
transform: translateY(40vh);
will-change: transform;
-webkit-backface-visibility: hidden;
backface-visibility: hidden;
-webkit-transition: all 1.7s cubic-bezier(0.22, 0.44, 0, 1);
transition: all 1.7s cubic-bezier(0.22, 0.44, 0, 1);
}
.content-title {
font-size: 12vh;
line-height: 1.4;
}
.background.up-scroll {
-webkit-transform: translate3d(0, -15vh, 0);
transform: translate3d(0, -15vh, 0);
}
.background.up-scroll .content-wrapper {
-webkit-transform: translateY(15vh);
-ms-transform: translateY(15vh);
transform: translateY(15vh);
}
.background.up-scroll + .background {
-webkit-transform: translate3d(0, 30vh, 0);
transform: translate3d(0, 30vh, 0);
}
.background.up-scroll + .background .content-wrapper {
-webkit-transform: translateY(30vh);
-ms-transform: translateY(30vh);
transform: translateY(30vh);
}
.background.down-scroll {
-webkit-transform: translate3d(0, -130vh, 0);
transform: translate3d(0, -130vh, 0);
}
.background.down-scroll .content-wrapper {
-webkit-transform: translateY(40vh);
-ms-transform: translateY(40vh);
transform: translateY(40vh);
}
.background.down-scroll + .background:not(.down-scroll) {
-webkit-transform: translate3d(0, -15vh, 0);
transform: translate3d(0, -15vh, 0);
}
.background.down-scroll + .background:not(.down-scroll) .content-wrapper {
-webkit-transform: translateY(15vh);
-ms-transform: translateY(15vh);
transform: translateY(15vh);
}
</style>
<div class="container">
<section class="background">
<div class="content-wrapper">
<p class="content-title">Full Page Parallax Effect</p>
<p class="content-subtitle">Scroll down!</p>
</div>
</section>
<section class="background">
<div class="content-wrapper">
<p class="content-title">Amazon forest</p>
<p class="content-subtitle">All the rendered pixels are super reall</p>
</div>
</section>
<section class="background">
<div class="content-wrapper">
<p class="content-title">Fireflies.</p>
<p class="content-subtitle">Long-exposure photo of fireflies in a darkened Japanese forest</p>
</div>
</section>
</div>
<script src='https://code.jquery.com/jquery-2.1.4.min.js'></script>
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js'></script>
<script id="rendered-js" >
var ticking = false;
var isFirefox = (/Firefox/i.test(navigator.userAgent));
var scrollSensitivitySetting = 30; // Increase/decrease to change sensitivity to trackpad gestures (up = less sensitive; down = more sensitive)
var slideDurationSetting = 600;
// Amount of time for which slide is "locked"
var currentSlideNumber = 0;
var totalSlideNumber = $(".background").length;
function parallaxScroll(evt) {
if (isFirefox) {
// Set delta for Firefox
delta = evt.detail * (-120);
} else {
// Set delta for all other browsers
delta = evt.wheelDelta;
}
if (ticking != true) {
if (delta <= -scrollSensitivitySetting) {
//Down scroll
ticking = true;
if (currentSlideNumber !== totalSlideNumber - 1) {
currentSlideNumber++;
nextItem();
}
slideDurationTimeout(slideDurationSetting);
}
if (delta >= scrollSensitivitySetting) {
//Up scroll
ticking = true;
if (currentSlideNumber !== 0) {
currentSlideNumber--;
}
previousItem();
slideDurationTimeout(slideDurationSetting);
}
}
}
function slideDurationTimeout(slideDuration) {
setTimeout(function() {
ticking = false;
}, slideDuration);
}
// Event listeners
var mousewheelEvent = isFirefox ? "DOMMouseScroll" : "wheel";
window.addEventListener(mousewheelEvent, _.throttle(parallaxScroll, 60), false);
// Slide motion
function nextItem() {
var $previousSlide = $(".background").eq(currentSlideNumber - 1);
$previousSlide.removeClass("up-scroll").addClass("down-scroll");
}
function previousItem() {
var $currentSlide = $(".background").eq(currentSlideNumber);
$currentSlide.removeClass("down-scroll").addClass("up-scroll");
}
</script>
첨부파일
- 이전글selectbox(셀렉트박스) option 선택 2023.06.04
- 다음글bxslider 사용법 2022.10.06