Skip to content

Commit

Permalink
Released 0.2.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
oblador committed Oct 10, 2013
1 parent 2fcf369 commit 1bcc56c
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 15 deletions.
70 changes: 61 additions & 9 deletions angular-scroll.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
angular.module('duScroll', ['duScroll.scroller', 'duScroll.scrollPosition', 'duScroll.requestAnimation', 'duScroll.smoothScroll']);
angular.module('duScroll', ['duScroll.scroller', 'duScroll.scrollPosition', 'duScroll.scrollspy', 'duScroll.requestAnimation', 'duScroll.smoothScroll']);


angular.module('duScroll.requestAnimation', []).
Expand Down Expand Up @@ -60,11 +60,13 @@ factory('scroller',
x: $window.scrollX
};
var delta = {
y: y - start.y,
x: x - start.x
y: Math.round(y - start.y),
x: Math.round(x - start.x)
};
if(!delta.x && !delta.y) return;

var frame = 0;
var frames = duration/60;
var frames = Math.ceil(duration/60);
var animate = function() {
frame++;
var percent = (frame === frames ? 1 : easeout(frame/frames));
Expand All @@ -91,25 +93,75 @@ factory('scroller',
);

angular.module('duScroll.smoothScroll', ['duScroll.scroller']).
directive('smoothScroll', function(scroller){
directive('duSmoothScroll', function(scroller){

return {
link : function($scope, $element, $attr){
var element = angular.element($element[0]);
element.on('click', function(e){
if(!$attr.href || $attr.href.indexOf('#') !== 0) return;
var elem = document.getElementById($attr.href.substring(1));
if(!$attr.href || $attr.href.indexOf('#') === -1) return;
var elem = document.getElementById($attr.href.replace(/.*(?=#[^\s]+$)/, '').substring(1));
if(!elem) return;

if (e.stopPropagation) e.stopPropagation();
if (e.preventDefault) e.preventDefault();


var offset = -($attr.offset ? parseInt($attr.offset, 10) : 0);
var pos = elem.getBoundingClientRect();

var delta = pos.top;
scroller.scrollDelta(0, pos.top, 1000);
scroller.scrollDelta(0, pos.top + (isNaN(offset) ? 0 : offset), 1000);
});
}
};
});

angular.module('duScroll.scrollspy', ['duScroll.scrollPosition']).
directive('duScrollspy', function(scrollPosition) {
var spies = [];
var currentlyActive;

function gotScroll(scrollY) {
var toBeActive;
for(var spy, scroll, pos, i = 0; i < spies.length; i++) {
spy = spies[i];
pos = spy.target.getBoundingClientRect();
if(pos.top + spy.offset < 20 && pos.top*-1 < pos.height) {
if(!toBeActive || toBeActive.top < pos.top) {
toBeActive = {
top: pos.top,
spy: spy
};
}
}
}
if(toBeActive) {
toBeActive = toBeActive.spy;
}
if(currentlyActive === toBeActive) return;
if(currentlyActive) currentlyActive.$element.removeClass('active');
if(toBeActive) toBeActive.$element.addClass('active');
currentlyActive = toBeActive;
}

function addSpy(target, $element, offset) {
if(!spies.length) {
scrollPosition.observe(gotScroll);
}
spies.push({
target: target,
$element: $element,
element: angular.element($element[0]),
offset: offset
});
}

return {
link: function ($scope, $element, $attr) {
if(!$attr.href || $attr.href.indexOf('#') === -1) return;
var target = document.getElementById($attr.href.replace(/.*(?=#[^\s]+$)/, '').substring(1));
if(!target) return;
addSpy(target, $element, -($attr.offset ? parseInt($attr.offset, 10) : 0));
}
};
});
2 changes: 1 addition & 1 deletion angular-scroll.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion angular-scroll.min.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-scroll",
"version": "0.1.0",
"version": "0.2.0",
"main": "angular-scroll.min.js",
"ignore": [
"**/.*",
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "angular-scroll",
"version": "0.1.0",
"description": "Scroll event listener and animated scrollTo",
"keywords": ["angular", "smooth-scroll", "scrollTo", "scrolling"],
"version": "0.2.0",
"description": "Scrollspy, animated scrollTo and scroll events",
"keywords": ["angular", "smooth-scroll", "scrollspy", "scrollTo", "scrolling"],
"main": "angular-scroll.min.js",
"repository": {
"type": "git",
Expand Down

0 comments on commit 1bcc56c

Please sign in to comment.