Giter Site home page Giter Site logo

alice's Introduction

Alice.js

Build Status

A Javascript library for attaching callbacks to vertical scroll positions. Functionality can be triggered based on the user scrolling (up or down) past a specific point, only once past a point in a specific direction, while the scroll position is within a certain range, or via custom tests.

Alice will attach herself as a jQuery plugin if jQuery exists. If jQuery does not exist, Alice will create an object alice in the global namespace.

With jQuery:

$.alice.after(function() {
  // Do something after 80 pixels
}, 80);

Without jQuery:

alice.after(function() {
  // Do something after 80 pixels
}, 80);

For the remainder of the documentation, the examples will be shown using syntax with jQuery.

Usage

Alice comes with several fancy helper methods help you get started writing cool stuff immediately.

At

The at method is simplest way to use Alice. The method takes a pair of arguments: a function to run once the window is scrolled past a specific top position and the top position (in pixels).

var myElement = $(".attached");

var callback = function( diff, goingDown ) {
      myElement.css("position", goingDown ? "fixed" : "absolute");
    }
  , scrollPosition = 320
;

$.alice.at(callback, scrollPosition);

Note that this example leveraged the goingDown argument. This second argument, goingDown, is (a boolean value) regarding whether the window is scrolling up or down at the moment the callback triggers.

After

The after method takes three arguments: a function to run once the window is scrolled past a specific top position, the top position (in pixels), and a (boolean) flag representing whether the callback should run repeatedly (or only once) after the window is scrolled past the specified position.

var myElement = $(".attached");

var callback = function( diff, goingDown ) {
      myElement.css("position", "fixed");
    }
  , scrollPosition = 320
  , repeat = false
;

$.alice.after(callback, scrollPosition, repeat);

Before

The before method is exactly the same as the after method except it works in the opposite direction.

var myElement = $(".attached");

var callback = function( diff, goingDown ) {
      myElement.css("position", "absolute");
    }
  , scrollPosition = 320
  , repeat = false
;

$.alice.before(callback, scrollPosition, repeat);

Range

The range method is basically a combination of after and before, and thus requires an additional top position to be defined. For this method, the callback function will run when the window is scrolled between the two given positions (ie. after the first position but before the second position).

var myElement = $(".flyAcross");

var callback = function( diff, goingDown ) {
      var leftAdjust = 200 * diff / (scrollPositionEnd - scrollPositionStart) - 100;
      myElement.css("left", diff + "%");
    }
  , scrollPositionStart = 320
  , scrollPositionEnd = 720
  , repeat = true
;

$.alice.range(callback, scrollPositionStart, scrollPositionEnd, repeat);

Note that this example leveraged the diff argument. The diff argument is the relative scroll position (in pixels) from scrollPositionStart.

Getting Alice

There are multiple production distributions of Alice. The standard build assumes that your application is already using the jQuery and lo-dash/underscore libraries, and that you would like the helper methods (at, after, before, and range) included.

Alice + helper methods:

Core-only versions:

License

* Copyright (c) 2012 Jacob Swartwood & American Eagle Outfitters Inc.
* Licensed under the MIT license

alice's People

Contributors

jswartwood avatar stinoga avatar workergnome avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.