Make fullpage divs with fade effect on scroll

I’d like to make a site with this site : https://www.squarespace.com/keanu as the design inspiration.

I tried using fullpage.js and it worked perfectly fine on the first two sections but had trouble on the third section because there are page elements fading in and out on scroll, which I think isn’t possible in fullpage.js as it won’t let me attach an event listener.

I’m a total beginner in javascript so writing my own is out of the question. So for the past 5 days, I’ve been trying my luck and was hoping I’d find some alternative for fullpage.js. And to be honest, I’m losing hope now.

If anyone could link me up to some plugin I could use, that would be a really great help.

I’ll attach the code I have for now w/o the fullpage.js. It only contains the fullpage divs, and some scrolling effect.

index.html (7.3 KB)

<!DOCTYPE html>
<html>
    <head>
        <style>
            body {
                font:20pt verdana;
            }
            
            a {
                display:block;
                color:red;
                margin-bottom:1em;
            }
            html, body, .section {
                /* Height and width fallback for older browsers. */
                height: 100%;
                width: 100%;
                
                /* Set the height to match that of the viewport. */
                height: 100vh;
                
                /* Set the width to match that of the viewport. */
                width: 100vw;
                
                /* Remove any browser-default margins. */
                margin: 0;
            }
            html {
                overflow: scroll;
                overflow-x: hidden;
            }
            ::-webkit-scrollbar {
                width: 0px;  /* remove scrollbar space */
                background: transparent;  /* optional: just make scrollbar invisible */
            }
            /* optional: show position indicator in red */
            ::-webkit-scrollbar-thumb {
                background: #FF0000;
            }
        /*    .section {
                width: 100%!important;
                position: absolute;
                left: 0;
                top: 0;
                visibility: hidden;
                opacity: 0;
                z-index: 0;
                transition: all .7s ease-in-out;
            }
        */    
            .section.active {
                visibility: visible;
                opacity: 1;
                z-index: 1;
            }
        </style>
        <script src="http://code.jquery.com/jquery-3.3.1.js"></script>
        <script type="text/javascript">
            (function() {
                var delay = false;
                $(document).on('mousewheel DOMMouseScroll', function(event) {
                    event.preventDefault();
                    if(delay) return;
                    delay = true;
                    setTimeout(function(){delay = false},400)
                    var wd = event.originalEvent.wheelDelta || -event.originalEvent.detail;
                    var a= document.getElementsByTagName('a');
                    if(wd < 0) {
                        for(var i = 0 ; i < a.length ; i++) {
                            var t = a[i].getClientRects()[0].top;
                            if(t >= 40) break;
                        }
                    }
                    else {
                        for(var i = a.length-1 ; i >= 0 ; i--) {
                            var t = a[i].getClientRects()[0].top;
                            if(t < -20) break;
                        }
                    }
                    if(i >= 0 && i < a.length) {
                        $('html,body').animate({
                            scrollTop: a[i].offsetTop
                        });
                    }
                });
            })(); 
            console.clear();
            $(document).ready(function(){
                $(window).scroll(function(){
                    $("#fading").css("opacity", 1 - $(window).scrollTop() / ($('#fading').height() / 2));
                });
            });
        </script>
    </head>
    <body>
        <div class="section" id="fading" style="background-color: black;">
            <a name="#A1">Tag #1.</a>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
        </div>
        <div class="section" id="fading" style="background-color: tomato;">
            <a name="#A2">Tag #2.</a>
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
        </div>
        <div class="section fading" style="background-color: white;">
            <a name="#A3">Tag #3</a>
            At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
            <a name="#A4">Tag #4.</a>
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
            <a name="#A5">Tag #5.</a>
            Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?
        </div>
    </body>
</html>

Yes that fullpage.js primarily seems to do some scroll snapping, while the page you linked to actually switches between slides by “scrolljacking” the page. Whether this latter technique makes for good UX is indeed debatable, but I think this page is a particularly bad example as it’s not accessible with the keyboard at all, and it gives the user no hint where they are currently navigating.

Anyway it’s not too difficult to implement with, er, vanilla jQuery:

You might then make your own plugin by adding that functionality to the jQuery prototype like so:

If you have questions about the code let me know!

2 Likes

To be honest, I have lots of questions about the code. Not because it’s difficult to understand or something, it’s just that I’m a total beginner in Javascript. :sweat_smile:

I’ll research more about what you posted and would let you know if there’s anything I still don’t understand. Thank you so much.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.