Minimalist Full Window Scroll Snap Plugin With jQuery - Download Minimalist Full Window Scroll Snap Plugin With jQuery

Download Minimalist Full Window Scroll Snap Plugin With jQuery

Posted on

This time I will share jQuery Plugin and tutorial about Minimalist Full Window Scroll Snap Plugin With jQuery, hope it will help you in programming stack.

Minimalist Full Window Scroll Snap Plugin With jQuery - Download Minimalist Full Window Scroll Snap Plugin With jQuery
File Size: 2.07 KB
Views Total: 3024
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A jQuery script that provides a simple way to create a full window one page scroll website with smooth scroll snapping functionality. After scrolling, the webpage will automatically scroll and smoothly snap to the next/prev content section depending on the current scroll position.

How to use it:

1. Create a group of DIV container for the content sections.

1 <div id="one" class="window section-1"></div>
2 <div id="two" class="window section-2"></div>
3 <div id="three" class="window section-3"></div>

2. Make the content sections full window.

01 body, html {
02   widht: 100%;
03   height: 100%;
04   margin: 0;
05   padding: 0;
06 }
07  
08 .window {
09   width: 100%;
10   height: 100%;
11 }

3. Place the needed jQuery library in the webpage.

1 <script src="//code.jquery.com/jquery.min.js"></script>

4. Declare section & current scroll position variables:

1 var sections = ['#one', '#two', '#three'];
2 var currentPos = 0;

5. The core function:

01 function scrollListen () {
02   $(window).on('scroll', function(){
03     $(window).off('scroll');
04  
05     let origin = $(window).scrollTop();
06     let delta = 0;
07  
08     $(window).on('scroll', () => {
09       delta = origin - $(window).scrollTop();
10  
11       if(Math.abs(delta) > 25){
12         $(window).off('scroll');
13  
14         if(delta < 0 && sections[currentPos + 1]){
15           currentPos++;
16  
17           setTimeout(function() {
18             $('html, body').animate({scrollTop: $(sections[currentPos]).offset().top}, 500, function() {
19               scrollListen();
20             });
21           }, 500);
22  
23         }else if(delta > 0 && sections[currentPos - 1]){
24           currentPos--;
25  
26           setTimeout(function() {
27             $('html, body').animate({scrollTop: $(sections[currentPos]).offset().top}, 500, function() {
28  
29               scrollListen();
30             });
31           }, 500);
32         }
33       }
34     });
35   });
36 }

6. Calculate the window’s height and apply the scroll snap functionality to the content sections.

01 $(function() {
02   $('.window').css({
03     'height': window.innerHeight,
04   });
05  
06   $(window).resize(() => {
07     $('.window').css({
08       'height': window.innerHeight,
09     });
10   });
11  
12   scrollListen();
13  
14 });

This awesome jQuery plugin is developed by THEAverageSpeedBurri. For more Advanced Usages, please check the demo page or visit the official website.

source : jqueryscript.net