Giter Club home page Giter Club logo

ng-curtain's Introduction

A set of pure AngularJS directives to create a wicked-cool "rising curtain" effect to unroll the sections of your website.


Usage

1. Install It

ngCurtain is available through Bower, so this is by far the easiest way to obtain it. Just run:

$ bower install --save-dev ng-curtain

This will download the latest version of ngCurtain and install it into your Bower directory (defaults to components). Boom!

2. Incorporate It

Now you have to add the script file to your application. You can, of course, just add a script tag. If you're using ngBoilerplate or any of its derivatives, simply add it to the vendor.js array of your Gruntfile.js:

vendor: {
  js: [
    // ...
    'vendor/ng-curtain/ng-curtain.min.js',
    // ...
  ]
},

However you get it there, as soon as it's in your build path, you need to tell your app module to depend on it:

angular.module( 'myApp', [ 'ngCurtain', /* other deps */ ] );

Also be sure to include the stylesheet. In ngBoilerplate, simply import ng-curtain.less into your main.less file.

Now you're ready to go! Sweet.

3. Use It

The markup for ngCurtain is fairly straightforward. There are two directives: ctnCurtains and ctnCurtain. The former is the main directive and wraps all content, accepting within it as many of the latter as necessary, each representing a separate curtain whose position to manage. Both can be used either as elements or as attributes.

For example, the typical structure of ngCurtain therefore looks something like this:

<ctn-curtains>
  <div ctn-curtain="first-section" ctn-cover="true">
    <!-- content here... -->
  </div>
  <div ctn-curtain="second-section">
    <!-- content here... -->
  </div>
  <div ctn-curtain="third-section">
    <!-- content here... -->
  </div>
  <div ctn-curtain="fourth-section">
    <!-- content here... -->
  </div>
</ctn-curtains>

How it Works

If you're just interested in using ngCurtain, you can ignore this section completely. But for those curious, this section contains an overview of how the code works.

The outer directive (ctnCurtains) contains the vast majority of the logic as methods on its scope. The inner directives (ctnCurtain) require the outer directive and call a method during their linking phase to register their presence.

After initialization of all the children, ctnCurtains calculates the positions of all the individual ctnCurtain elements that registered themselves, calculates the total window height, and determines which curtains to start where based on the current value of $location.path(). This same process is repeated every time the window is resized.

Technically, all cards start positioned at 0,0 and the window's height is manually calculated and applied as the sum of the heights of the individual curtains.

When the browser window scrolls, the ctnCurtains directive determines whether we are scrolling within a curtain, beyond a curtain, or above a curtain and arranges the positions and stacks appropriately and applies translateY operations to change the current vertical position of the curtain relative to the current (virtual) scroll position. That probably sounds confusing, but if you look at the code, it's pretty straightforward.

Contributing

Contributions are encouraged! There is a lot to be done.

Shameless Self-Promotion

Like ngCurtain? Star this repository to let me know! If this got you particulary tickled, you can even follow me on GitHub, Twitter, Google+, or LinkedIn.

Enjoy.

ng-curtain's People

Contributors

joshdmiller avatar

Watchers

Todd Forsberg avatar James Cloos 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.