How to make vertical slider on scroll without libs.
Created
August 26, 2019 18:26
-
-
Save Adefful/0948eedfec70b39e2356bc912d43d25b to your computer and use it in GitHub Desktop.
Vertical Slider Animation [JQuery]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="slide s1"><img src="http://blog.domainparking.ru/wp-content/uploads/2019/04/dotmusic-1024x683.jpeg" alt=""></div> | |
<div class="slide s2"><img src="https://i.artfile.me/wallpaper/10-04-2018/5184x3456/muzyka--drugoe-ruki-1326150.jpg" alt=""></div> | |
<div class="slide s1"><img src="https://images.wallpaperscraft.ru/image/dj_naushniki_ustanovka_122020_4135x2756.jpg" alt=""></div> | |
<div class="slide s2"><img src="https://vibirai.ru/image/1259687.jpg" alt=""></div> | |
<div class="slide s1"><img src="https://wallbox.ru/wallpapers/main/201134/gitara-muzyka-siniy-e56f2fa.jpg" alt=""></div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var next = 0; | |
var timeout = 1000; | |
var scrollBlock = () => { | |
$(window).bind("mousewheel DOMMouseScroll MozMousePixelScroll", (event) => { | |
$(window).unbind("mousewheel DOMMouseScroll MozMousePixelScroll"); | |
$(window).bind("mousewheel DOMMouseScroll MozMousePixelScroll",freeze); | |
setTimeout(scrollBlock,timeout); | |
var st = parseInt(event.originalEvent.wheelDelta || -event.originalEvent.detail); | |
console.log(st); | |
if (st <= 0 ) { | |
// downscroll code | |
next = next == $(".slide").length-1 ? next : (next += 1); | |
console.log(next); | |
$("html, body").animate( | |
{ | |
scrollTop: $(".slide") | |
.eq(next) | |
.offset().top | |
}, | |
timeout | |
); | |
} else { | |
// upscroll code | |
next = next == 0 ? next : next -= 1; | |
$("html, body").animate( | |
{ | |
scrollTop: $(".slide") | |
.eq(next) | |
.offset().top | |
}, | |
timeout | |
); | |
} | |
}); | |
}; | |
var freeze = () => { | |
$("html, body"). | |
scrollTop = $(".slide") | |
.eq(next) | |
.offset().top; | |
}; | |
scrollBlock(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.slide | |
width: 100% | |
height: 100vh | |
background-size: cover | |
img | |
width: 100% | |
height: 100% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment