npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ng-magics

v1.0.1

Published

AngularJS companion module for ScrollMagic

Downloads

26

Readme

ng-magics

ng-magics (full name: ng-magics-crawl) is Angular 1.x companion for ScrollMagic, a de facto JavaScript tool for top grade scrolling animation.

Build Status

Description

The module introduces several Angular directives and services to do scrolling sorcery in Angular-friendly, declarative way:

<div ng-class="{ activeClass: isActive }>{{ isActive ? 'active' : '' }}</div>
<div magics-scene magics-spy="isActive" magics-spy-progress="progressHandler">{{ progress }}</div>
// may use built-in `debounce` or `throttle` services for best performance 
$scope.progressHandler = throttle((e) => {
	$scope.progress = Math.round(e.progress * 100) + '%';
	$scope.$apply();
}, 100);

Instead of jQuery-fashioned, harder to maintain code:

var scene = new ScrollMagic.Scene({
	triggerElement: '#element',
	// manually calculated number
	// or a function that calculates it from responsive elements
	duration: 100  
})
	.setClassToggle('#anotherElement', 'activeClass')
	.on('enter leave', (e) => {
		$('#anotherElement').text(e.type == 'enter' ? 'active' : ''); 
	})
	.on('progress', (e) => {
		$('#element').text(Math.round(e.progress * 100) + '%'); 
	});

new ScrollMagic.Controller()
	.addscene(scene);

Even if the full power of ScrollMagic is demanded for some serious black arts, ScrollMagic API is available through Angular services.

Glossary

Stage

The stage behind the sequence of scenes which does no actions and holds no logic. Known as controller in ScrollMagic but renamed to stage in ng-magics to match its role better and avoid confusion with Angular controllers (it even asked for that in person).

It defines root element for the act (any container, but, more frequently, window) and the axis of scrolling. All the relevant scenes are attached to it, the controller also defines default settings for them.

The stage holds global information (current position, direction, container) about the stage. There's not much to say about it besides that.

Scene

The place where the magic happens in ScrollMagic. The scene triggers events on its beginning, continuation and finale, any sort of change (likely visual) can be caused by them.

ScrollMagic doesn't perform any visual effects by itself, they have to be implemented by either CSS3 classes or third-party animation library (TweenMax or TweenLite).

A scene may be some abstract start point and have no end, but ng-magics magics-scene directive limits the scene to the bounds of specific DOM element.

Pin

Fixes the element in viewport during the current scene, until it is unpinned manually, or the scene is over. While ScrollMagic can pin an arbitrary element, ng-magics magics-pin directive is supposed to pin only scene's children.

Spy

The concept of scene spies is specific to ng-magics. A spy directive, magics-spy binds scope properties to the events ('enter', 'leave' and 'progress') of the relevant scene.

Prerequisites

The module depends on ScrollMagic (ScrollMagic global) and its GSAP and addIndicators (for enabled magicsProvider.debug) plugins that should be loaded before the application is bootstrapped.

It also depends on GreenSock TweenMax or TweenLite libraries (TweenMax or TweenLite global) and their ScrollToPlugin plugin for ScrollMagic animations, one of the libraries should be loaded before ScrollMagic.

API

##magicsScene

Creates a new scene or reuses the existing one on either the stage specified by magicsStage directive or 'default' stage.

###Directive Info

###Usage

  • as attribute:
    <ANY
      [magics-scene="string"]
      [magics-scene-options="Object"]>
    ...
    </ANY>

####Arguments

| Param | Type | Details | | :--: | :--: | :--: | | magicsScene(optional) | string | Scene name. | | magicsSceneOptions(optional) | Object | Options that are used on scene creation. |

##magicsSpy

Sets up a spy for the scene specified by either parent magicsScene directive or magicsSpyScene attribute.

###Directive Info

###Usage

  • as attribute:
    <ANY
      [magics-spy="expression"]
      [magics-spy-scene="string"]
      [magics-spy-progress="expression"]>
    ...
    </ANY>

####Arguments

| Param | Type | Details | | :--: | :--: | :--: | | magicsSpy(optional) | expression | Scope variable flag (read-only). | | magicsSpyScene(optional) | string | Scene name. | | magicsSpyProgress(optional) | expression | Scene progress callback function. |

##magicsStage

Creates a new stage or reuses the existing one.

###Directive Info

###Usage

  • as attribute:
    <ANY
      [magics-stage="string"]
      [magics-stage-options="Object"]>
    ...
    </ANY>

####Arguments

| Param | Type | Details | | :--: | :--: | :--: | | magicsStage(optional) | string | Stage name. | | magicsStageOptions(optional) | Object | Options that have to be passed to magics.stage. |

Example

A demo is available, it briefly depicts the features and the concepts behind the module.