0.1.3 • Published 5 years ago

@hawezo/autoscroll.js v0.1.3

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
5 years ago

autoscroll.js

Settings

OptionsDefaultDescription
debugfalseEnables console debugging.
scrollDuration800The duration in milliseconds of the scroll animation.
forceFitfalseEnable to force a section to fit.
offset0The offset of the section scroll.
beforeScrollCallbackundefinedA callback that will be called right before a scroll. If it returns false, the scroll will not happen.
scrollCallbackundefinedA callback that will be called right after a scroll.
nextSectionVisibilityThresold15If forceFit is disabled, this options defines the needed percentage of visibility a section must have to be automatically scrolled to.
fitToScreenfalseWill set the height of all sections to the height of the current viewport.

Usage

As a script

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript" src="../dist/autoscroll.js"></script>
<script>
    autoscroll({
        scrollDuration: 1000,
        debug: true,
        forceFit: true,
        fitToScreen: true,
        sections: {
            div1: {
                targetDown: 'div2',
                targetUp: 'div1',
                id: '#div1',
            },
            div2: {
                targetDown: 'div3',
                targetUp: 'div1',
                id: '#div2',  
            },
            div3: {
                targetDown: 'div3',
                targetUp: 'div2',
                id: '#div3',
            }
        }
    });
</script>

With import

import autoscroll from '@hawezo/autoscroll.js';

const autoscroll = autoscroll({
    scrollDuration: 1000,
    debug: true,
    forceFit: true,
    fitToScreen: true,
    sections: {
        div1: {
            targetDown: 'div2',
            targetUp: 'div1',
            id: '#div1',
        },
        div2: {
            targetDown: 'div3',
            targetUp: 'div1',
            id: '#div2',
        },
        div3: {
            targetDown: 'div3',
            targetUp: 'div2',
            id: '#div3',
        }
    }
});

Example HTML

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>autoscroll.js</title>

    <style>
        html, body {
            margin: 0;
            padding: 0;
        }
    </style>
</head>
<body>
    <body>
        <section id="div1" style="height: 100vh; background-color: red;">
        </section>
        <section id="div2" style="height: 100vh; background-color: green;">
        </section>
        <section id="div3" style="height: 100vh; background-color: blue;">
        </section>

        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
        <script type="text/javascript" src="../dist/autoscroll.js"></script>
        <script>
            autoscroll({
                scrollDuration: 1000,
                debug: true,
                forceFit: true,
                fitToScreen: true,
                sections: {
                    div1: {
                        targetDown: 'div2',
                        targetUp: 'div1',
                        id: '#div1',
                    },
                    div2: {
                        targetDown: 'div3',
                        targetUp: 'div1',
                        id: '#div2',  
                    },
                    div3: {
                        targetDown: 'div3',
                        targetUp: 'div2',
                        id: '#div3',
                    }
                }
            })
        </script>
    </body>
</body>
</html>
0.1.3

5 years ago

0.1.1

5 years ago

0.1.0

5 years ago