Code Monkey home page Code Monkey logo

naivescroll's Introduction

naiveScroll

Tiny jQuery full page scroll effect plugin.

Features

  • Override mouse whell event to scroll full page.
  • Minimum extra HTML elements required.
  • Prevents redundant events from being triggered.
  • Provide API to manually scroll up or down.
  • Tiny size, 1KB zipped.

Usage

HTML

Simply use basic <section> element to contain the pages you need to scroll. No other class or properties is required. You can also modify JS code to use other DOM element as container.

<body>
    <section></section>
    <section></section>
    <section></section>
</body>

CSS

You can custom the HTML <section> created above as you like. For example, you can use diffferent background images for each <section> as below.

Firstly add some classes to distinguish each class.

<body>
    <section class="page1"></section>
    <section class="page2"></section>
    <section class="page3"></section>
</body>

Then custom each sections with your styles.

/* use background color */
.page1 {
    top: 0;
    background-color: lightcoral;
}

/* or use background image */
.page2 {
    top: 100%;
    background: url("foo.jpg") no-repeat center center;
    background-size: cover;
}

/* notice the top property */
.page3 {
    top: 200%;
    background-color: lightblue;
}

JS

Once you finish the static content, you can easily enable naiveScroll with jQuery.

Enable mouse wheel scroll effect

Just call init method and test it out.

$(this)._naiveScroll.init();

Bind scroll effect to other events

Now naiveScroll only supports scroll up or down one page per time. You can modify its source code to support your compenents.

$('#upBtn').click(function () {
    $(this)._naiveScroll.triggerScroll(100);
});
    
$('#downBtn').click(function () {
    $(this)._naiveScroll.triggerScroll(-100);
});

Have fun!

naivescroll's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.