Giter Site home page Giter Site logo

haensl / nganimatedscroll Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 1.0 23 KB

A promise based angular.js service to facilitate animated scrolling.

License: MIT License

JavaScript 100.00%
angularjs angular scrolling animation angular-service promise promises module angular1 angular1-x

nganimatedscroll's Introduction

DEPRECATED: ngAnimatedScroll

A promise based angular.js service to facilitate animated scrolling

Deprecation notice

Due to the end of life of Angular.js, this module is deprecated and no longer maintained.

NPM

Features

  • Exposes a service that scrolls an arbitrary element to another element's location.
  • Promise enabled: The service returns a promise and resolves upon completion of the scroll operation.
  • Selector enabled: Use CSS selectors to specify to which element to scroll.
  • Leverages window.getAnimationFrame() for a smooth and efficient scroll animation
  • Clean: No classes, no jQuery, no CSS, just plain Angular.js

Installation

  1. Install the ngAnimatedScroll package

via NPM:

npm install ng-animated-scroll --save

or Bower:

bower install ng-animated-scroll --save
  1. Include the library into your application:

if installed via NPM include from node_modules:

<script src="/node_modules/ng-animated-scroll/dist/ngAnimatedScroll.service.min.js"></script>

if installed via Bower include from bower_components:

<script src="/bower_components/ng-animated-scroll/dist/ngAnimatedScroll.service.min.js"></script>

Usage

  1. Add a dependency to AnimatedScroll to your app

    angular.module('myApp', ['AnimatedScroll']);
  2. Inject the animatedScroll service into your directive, factory, controller, etc. and call it's scroll() method.

    angular.module('myController', ['animatedScroll', function(animatedScroll) {
      animatedScroll.scroll(elementToScrollTo);
    }]);

Example: Simple scroll operation

angular.module('myController', ['animatedScroll', function(animatedScroll) {
  var elementIWantToScrollTo = document.getElementById('anElementIWantToScrollTo');
  animatedScroll.scroll(elementIWantToScrollTo);
}]);

Example: Using CSS selectors

angular.module('myController', ['animatedScroll', function(animatedScroll) {
  animatedScroll.scroll('#someElement');
}]);

Example: Leveraging the promise

angular.module('myController', ['animatedScroll', function(animatedScroll) {
  var elementIWantToScrollTo = document.getElementById('anElementIWantToScrollTo');
  animatedScroll.scroll(elementIWantToScrollTo)
    .then(function(element) {
      // do something after the element was scrolled into view
      // element = elementIWantToScrollTo
    });
}]);

Example: Scrolling within an Element

angular.module('myController', ['animatedScroll', function(animatedScroll) {
  var listItemIWantToScrollTo = document.getElementById('listItemIWantToScrollTo');
  var list = document.getElementById('aList');
  animatedScroll.scroll(elementIWantToScrollTo, {
    scrollElement: list
  }).then(function(element) {
    // do something after the the list item was scrolled into view
    // element = listItemIWantToScrollTo
  });
}]);

Arguments

element (required)

Type: Element | angular.element | selector (string)

The element to scroll to. This can be an angular.element, (HTML)Element or CSS selector string.

options (optional)

Type: Object

Options for the scroll operation. (See Options)

Options

duration

Type: Integer Default: 800

The duration of the scroll animation in milliseconds.

offset

Type: Integer Default: 0

An offset to the element's top at which to stop scrolling.

easing

Type: String Default: easeInOutQuart

The easing function to be used for the animation. Currently supported are:

  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint
  • none (no easing)

scrollElement

Type: Element | angular.element | selector (string) Default: window

The element to scroll. This can be an angular.element, (HTML)Element or CSS selector string.

Credits

ngSmoothScroll by David Oliveros which formed the base for ngAnimatedScroll

https://github.com/d-oliveros/ngSmoothScroll

The MIT License (MIT)

Copyright © Hans-Peter Dietz | @h_p_d | [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nganimatedscroll's People

Contributors

haensl avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

lazuraslong

nganimatedscroll's Issues

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.