Skip to content

Commit

Permalink
Added built library files and docs.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpocklin committed Jun 2, 2015
1 parent 89d5e07 commit 0c8f518
Show file tree
Hide file tree
Showing 21 changed files with 12,897 additions and 0 deletions.
91 changes: 91 additions & 0 deletions dist/angular-scroll-animate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
'use strict';
angular.module('angular-scroll-animate', []);// Source: src/angular-scroll-animate.js
/**
* @ngdoc directive
* @name angular-scroll-animate.directive:when-visible
* @restrict A
*
* @description
* Allows method hooks into the detection of when an element is scrolled into or out of view.
*/
angular.module('angular-scroll-animate', []).directive('whenVisible', ['$document', '$window',
function($document, $window) {

var determineWhereElementIsInViewport =
function($el, viewportHeight, whenVisibleFn, whenNotVisibleFn, delayPercent, scope) {

var elementBounds = $el[0].getBoundingClientRect();

var panelTop = elementBounds.top;
var panelBottom = elementBounds.bottom;

// pixel buffer until deciding to show the element
var delayPx = delayPercent * elementBounds.height;

var bottomVisible = (panelBottom - delayPx > 0) && (panelBottom < viewportHeight);
var topVisible = (panelTop + delayPx <= viewportHeight) && (panelTop > 0);

if ($el.data('hidden') && bottomVisible || topVisible) {
whenVisibleFn($el, scope);
$el.data('hidden', false);
}

// scrolled out from scrolling down or up
else if (!($el.data('hidden')) && (panelBottom < 0 || panelTop > viewportHeight)) {
whenNotVisibleFn($el, scope);
$el.data('hidden', true);
}
};

return {
restrict: 'A',
scope: {
whenVisible: '&',
whenNotVisible: '&?',
delayPercent: '=?'
},

controller: ['$scope', function(scope) {
if (!scope.whenVisible || !angular.isFunction(scope.whenVisible())) {
throw new Error('Directive: angular-scroll-animate \'when-visible\' attribute must specify a function.');
}

if (scope.whenNotVisible && !angular.isFunction(scope.whenNotVisible())) {
throw new Error('Directive: angular-scroll-animate \'when-not-visible\' attribute must specify a function.');
}

if (scope.delayPercent) {

var delayPercent = parseFloat(scope.delayPercent);

if ((Number.isNaN(delayPercent)) || (delayPercent < 0 || delayPercent > 1)) {
throw new Error('Directive: angular-scroll-animate \'delay-percent\' attribute must be a decimal fraction between 0 and 1.');
}
}
}],

link: function(scope, el, attributes) {

var delayPercent = attributes.delayPercent || 0.25; // lower = more eager to hide / show, higher = less eager

var onScroll = function() {

var document = $document[0].documentElement;
var viewportHeight = document.clientHeight;

determineWhereElementIsInViewport(el, viewportHeight,
scope.whenVisible(), scope.whenNotVisible(), delayPercent, scope);
};

var unbindDocumentEvents = $document.on('scroll', onScroll);
var unbindWindowEvents = angular.element($window).on('resize orientationchange', onScroll);

scope.$on('$destroy', unbindDocumentEvents);
scope.$on('$destroy', unbindWindowEvents);

// initialise
el.data('hidden', true);
scope.$evalAsync(onScroll);
}
};
}]);
45 changes: 45 additions & 0 deletions docs/css/animations.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.slide-reveal.ng-enter {
-webkit-transition:0.5s linear all;
-moz-transition:0.5s linear all;
-o-transition:0.5s linear all;
transition:0.5s linear all;

opacity:0.5;
position:relative;
opacity:0;
top:10px;
}
.slide-reveal.ng-enter-active {
top:0;
opacity:1;
}

.expand.ng-enter {
-webkit-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
-moz-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
-o-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;

opacity:0;
max-height:0;
overflow:hidden;
}
.expand.ng-enter-active {
opacity:1;
max-height:40px;
}

.expand.ng-leave {
-webkit-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
-moz-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
-o-transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;
transition:0.3s cubic-bezier(0.250, 0.460, 0.450, 0.940) all;

opacity:1;
max-height:40px;
overflow:hidden;
}
.expand.ng-leave-active {
opacity:0;
max-height:0;
}
Loading

0 comments on commit 0c8f518

Please sign in to comment.