GithubHelp home page GithubHelp logo

oblador / angular-scroll Goto Github PK

View Code? Open in Web Editor NEW
1.5K 30.0 234.0 400 KB

Scrollspy, animated scrollTo and scroll events for angular.js

Home Page: http://oblador.github.io/angular-scroll/

License: MIT License

HTML 36.70% JavaScript 63.30%

angular-scroll's Introduction

angular-scroll

Angular is only dependency (no jQuery). 8K minified or 2K gzipped.

Example

Check out the live demo or the source code.

Install

With bower:

$ bower install angular-scroll

With npm (for use with browserify):

$ npm install angular-scroll

You can also download the production version or the development version.

If you prefer a CDN hosted version (which might speed up your load times), check out cdnjs.com/libraries/angular-scroll.

Don't forget to add duScroll to your module dependencies.

angular.element Scroll API

This module extends the angular.element object with a few jQuery like functions. Note that $document is an angular.element, for usage example see below. In case of name collisions existing jQuery or jqlite functions will be preserved, just use the prefixed version: ie .duScrollTo() instead of .scrollTo().

.scrollTo( left, top [, duration [, easing ] ] )

Scrolls the element/window to the specified left/top position. If duration is specified the scrolling is animated for n milliseconds. If easing is ommited the animation will default to the duScrollEasing function.

.scrollTo( element [, offset, [, duration [, easing ] ] ] )

Alias of .scrollToElement.

.scrollToElement( element [, offset, [, duration [, easing ] ] ] )

Scrolls to the specified element, if offset is passed it will be subtracted from the elements position which is good if one uses floating menus.

.scrollToElementAnimated( element [, offset, [, duration [, easing ] ] ] )

Convenience function. Works exactly the same as scrollToElement but uses the default values from duScrollOffset, duScrollDuration and duScrollEasing unless otherwise specified.

.scrollTop|scrollLeft( )

Returns current scroll position.

.scrollTop|scrollLeft( top [, duration [, easing ] ] )

Scrolls to specified position in either axis, with optional animation.

.scrollTopAnimated|scrollLeftAnimated( top [, duration [, easing ] ] )

Convenience function like scrollToElementAnimated but for scrollTop/scrollLeft.

Promises

Animated scrolling returns a $q promise, it will resolve when the scrolling has finished or be rejected if cancelled (by starting another scroll animation before it finished).

Example

angular.module('myApp', ['duScroll']).
  controller('myCtrl', function($scope, $document) {
    var top = 400;
    var duration = 2000; //milliseconds

    //Scroll to the exact position
    $document.scrollTop(top, duration).then(function() {
      console && console.log('You just scrolled to the top!');
    });

    var offset = 30; //pixels; adjust for floating menu, context etc
    //Scroll to #some-id with 30 px "padding"
    //Note: Use this in a directive, not with document.getElementById 
    var someElement = angular.element(document.getElementById('some-id'));
    $document.scrollToElement(someElement, offset, duration);
  }
);

The above example can be achieved by configuration instead of arguments:

angular.module('myApp', ['duScroll'])
  .value('duScrollDuration', 2000)
  .value('duScrollOffset', 30)
  .controller('myCtrl', function($scope, $document) {
    $document.scrollTopAnimated(400).then(function() {
      console && console.log('You just scrolled to the top!');
    });

    var someElement = angular.element(document.getElementById('some-id'));
    $document.scrollToElementAnimated(someElement);
  }
);

Directives

du-smooth-scroll

Provides smooth anchor scrolling.

<a href="#anchor" du-smooth-scroll>Scroll it!</a>

If you, for some reason, do not want to use the href attribute as fallback, just use the du-smooth-scroll attribute instead but without leading #. Example: <a du-smooth-scroll="anchor">.

du-scrollspy

Observes whether the target element is at the top of the viewport (or container) and adds an active class if so. Takes optional offset and duration attributes which is passed on to .scrollTo,

<a href="#anchor" du-scrollspy>Am i active?</a>

or together with Bootstrap

<ul class="nav navbar-nav">
  <li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
</ul>

du-spy-context

Enables multiple sets of spies on the same target element. Takes optional offset attribute to

<ul du-spy-context class="nav navbar-nav">
  <li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
</ul>
<ul du-spy-context class="nav navbar-nav">
  <li du-scrollspy="anchor"><a href="#anchor">Link</a></li>
</ul>

du-scroll-container

Modifies behavior of du-scrollspy and du-smooth-scroll to observe/scroll within and element instead of the window/document. Good for modals/elements with overflow: auto/scroll.

<div du-scroll-container>
  <p id="top">This is the top</p>
  <p id="anchor">Scroll to me, or <a href="#top" du-smooth-scroll>the top</a></p>
</div>

If your links lie outside of the scrollable element, wrap them with the du-scroll-container directive and send the element id as argument:

<ul du-scroll-container="scroll-container">
  <li><a href="#anchor" du-smooth-scroll>Link</a></li>
</ul>
<div id="scroll-container">
  [...]
</div>

The directives play well together, try the demo or inspect its source code.

<ul du-spy-context du-scroll-container="scroll-container">
  <li><a href="#anchor" offset="30" du-smooth-scroll du-scrollspy>Link</a></li>
</ul>
<ul du-spy-context du-scroll-container="scroll-container">
  <li><a href="#anchor" offset="30" du-smooth-scroll du-scrollspy>Link</a></li>
</ul>
<div id="scroll-container">
  [...]
</div>

Observing Scroll Position

NOTE: the $duScrollChanged event and the scrollPosition service are deprecated. Use angular.element().on() together with .scrollTop() instead.

angular.module('myApp', ['duScroll']).
  controller('MyCtrl', function($scope, $document){
    $document.on('scroll', function() {
      console.log('Document scrolled to ', $document.scrollLeft(), $document.scrollTop());
    });
    var container = angular.element(document.getElementById('container'));
    container.on('scroll', function() {
      console.log('Container scrolled to ', container.scrollLeft(), container.scrollTop());
    });
  }
);

Configuration

Scroll speed

Duration is defined in milliseconds.

To set a scroll duration on a single anchor:

<a href="#anchor" du-smooth-scroll duration="5000">Scroll it!</a>

To change the default duration:

angular.module('myApp', ['duScroll']).value('duScrollDuration', 5000);

Scroll easing

Set the duScrollEasing value to a function that takes and returns a value between 0 to 1. Here's a few examples to choose from.

function invertedEasingFunction(x) {
  return 1-x;
}
angular.module('myApp', ['duScroll']).value('duScrollEasing', invertedEasingFunction);

You can also pass a custom easing function as the fourth argument in scrollTo.

Debounce Scroll Events

Set the duScrollSpyWait value in milliseconds to debounce the handler and prevent it from triggering frequent events and increase performance for large pages and/or navigations with expanding nodes.

angular.module('myApp', ['duScroll']).value('duScrollSpyWait', 1000);

Greedy option

Set the duScrollGreedy value to true if the elements you are observing are not wrapping the whole section you want to observe, but merely the first one in the section (such as headlines).

angular.module('myApp', ['duScroll']).value('duScrollGreedy', true);

Offset

To change default offset (in pixels) for the du-smooth-scroll directive:

angular.module('myApp', ['duScroll']).value('duScrollOffset', 30);

When to cancel scroll animation

Specify on which events on the container the scroll animation should be cancelled by modifying duScrollCancelOnEvents, set to false to disable entirely as shown below. Defaults to scroll mousedown mousewheel touchmove keydown.

angular.module('myApp', ['duScroll']).value('duScrollCancelOnEvents', false);

Bottom spy

To make the last du-scrollspy link active when scroll reaches page/container bottom:

angular.module('myApp', ['duScroll']).value('duScrollBottomSpy', true);

Active class

Specify the active class name to apply to a link when it is active, default is active.

angular.module('myApp', ['duScroll']).value('duScrollActiveClass', 'custom-class');

Events

The duScrollspy directive fires the global events duScrollspy:becameActive and duScrollspy:becameInactive with an angular.element wrapped element as first argument and the element being spied on as second. This is nice to have if you want the URL bar to reflect where on the page the visitor are, like this:

angular.module('myApp', ['duScroll']).
  run(function($rootScope) {
    if(!window.history || !history.replaceState) {
      return;
    }
    $rootScope.$on('duScrollspy:becameActive', function($event, $element, $target){
      //Automaticly update location
      var hash = $element.prop('hash');
      if (hash) {
        history.replaceState(null, null, hash);
      }
    });
  });

Building

$ npm install
$ bower install
$ gulp

Tests

Unit tests

$ npm test

End to end tests

$ npm run update-webdriver
$ npm run protractor

angular-scroll's People

Contributors

1wheel avatar a-bashtannik avatar alexcppns avatar atefbb avatar garbados avatar gnomeontherun avatar homerjam avatar jacksonrayhamilton avatar jalexanderfox avatar jrr avatar larrifax avatar martyix avatar mchambaud avatar mkoryak avatar oblador avatar pkaminski avatar szantner avatar tschneid avatar twhitbeck avatar varya avatar xperiments avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

angular-scroll's Issues

Scrollspy active class is offset when dynamically loading content for the container

I am trying to get the scrollspy working with dynamically loaded content. What seems to be happening is the scrollspy is loaded and hooked up to the DOM before my content is done loading, thus offsetting the position of the elements. When you then scroll down the page the active class on the nav elements is offset form the actual element position.

Scroll spy with dinamically loaded content

If the template containing scrolling markup is loaded dynamically, then scroll spy stops working after template was reloaded for the first time.

Example at http://plnkr.co/edit/FdECKs0ARM89qEB5xitv?p=preview demonstrates simple navigation between two documents, which of those represented by the same layout. If user clicks on 'Document 1', scroll spy works and active class is assigned to the links. However if user clicks on 'Document 2', scroll spy stops working. Only page reload can help.

What happens here is that on dynamic reload container is destroyed while the context remains. I didn't figure out yet why exactly this happens. If it cannot be fixed I can suggest extend condition (!context.container) in addSpy function. In the example above, after user clicks on the second link context.container is not empty, it just not attached to the DOM.

Using angular-scroll inside a directive

Hi,

Just wondering if its possible to do this? There are no examples and I can't seem to get it working. If I move the same logic into a controller it works fine.

I'm using the container example but instead of having ng-click bound to the controller there is a directive that responds to a change in a custom data attribute within the container div and it should scroll to that id.

Focus after scroll

I am trying to get the a link to scroll the screen to an element, and then focus on a form after the scroll is over.

However, when I try to create a directive which adds an event to focus after on $element.on('scroll', ...), that event never seems to be called.

http://plnkr.co/edit/sb3UvK?p=preview

Make parent <li> "active" too

Hi,
I'm beginning in the WEB world, and I'm using angular and bootstrap.
I see that bootstrap apply CSS to the 'li' element not to the 'a' element when active, can angular-scroll do this automatically?

I do this to my app, but don't know if is the best solution:

  run(function($rootScope, $location){
    $rootScope.$on('duScrollspy:becameActive', function($event, $element){
        if($element.parent()[0].tagName == "LI"){
            $element.parent().addClass("active");
        }       
    });
    $rootScope.$on('duScrollspy:becameInactive', function($event, $element){
        if($element.parent()[0].tagName == "LI"){
            $element.parent().removeClass("active");
        }       
    });

Scroll updates are too slow/incorrect when using duScrollGreedy

I've made a plunkr to show this behavior: http://plnkr.co/edit/UBHW00LzF81zgLSgGj0Y?p=preview

If the container is scrolled too quickly, angular-scroll is not picking up that the elements been scrolled past. If duScrollGreedy is enabled, it should check to see if the scroll position has passed the scrollSpy element, regardless of scroll speed. Without this, duScrollGreedy barely works for smaller elements.

Along with this, duScrollGreedy should select the previous scrollSpy element when scrolling up, instead it stays with the last passed scrollSpy.

See this image for an example:
screen shot 2014-09-04 at 4 59 54 pm

Section 1 should be selected instead of Section 2 as we've scrolled past that element. This becomes especially confusing if you have large amounts of space between scrollSpy elements as neither can be on screen, yet the element past the bottom of the visible screen will still show as active.

For a working example of this technique, check out the Bootstrap Javascript page: http://getbootstrap.com/javascript/#scrollspy. This allows headings to be used as the scrollSpy elements, but still updates regardless of scroll speed.

Cannot read property 'spies' of undefined

its seems due to when I set

ng-show directive on the parent element of a scroll directive

located at function:

 p = function(e) {
      var t = d(e);
      d(e).spies.push(e),
   ...

Scroll spy events issue with $rootScope.$apply();

I implemented angular-scroll successfully however when I try to show the url I get multiple page refresh and is like the scroll event gets triggered randomly multiple times while navigating to the section I've clicked.
I thinks the problem is in "$rootScope.$apply();"

'use strict';

angular.module('ngscrollApp', [
'ngCookies',
'ngResource',
'ngSanitize',
'ngRoute',
'ui.bootstrap',
'duScroll'
])
.config(function ($routeProvider, $locationProvider) {
$routeProvider
.when('/', {
templateUrl: 'views/main.html',
controller: 'MainCtrl'
})
.otherwise({
redirectTo: '/'
});
$locationProvider.html5Mode(true);
})
.value('duScrollDuration', 5000)
.run(function($rootScope, $location){
$rootScope.$on('duScrollspy:becameActive', function($event, $element){
//Automaticly update location
var hash = $element.prop('hash');
if(hash) {
console.log($element);
$location.hash(hash.substr(1)).replace();
$rootScope.$digest();
}
});
});

Custom container

Very nice utility I really like it, That being said I had to modify it to work within my framework which does not use the window as the main scroll container instead i have a sub section that is the main container which is used to scroll.

Just a suggestion it would be nice if you could define a custom scrollable container by ID

Not changing URL on smooth scroll

Looks like the directive is preventing the URL changing when clicking on a link with smoothscroll directive applied. This is pretty important for being able to share the link to a specific section in some cases. Any thoughts on this?

angular-scroll with ng-repeat elements

I was using scrollspy and jquery smooth scroll but since I migrated to angular I can't use it anymore. Your project looks nice for doing that, but it is not working for me because my nav (menu) and sections are generated dynamically. Something like this:

  <div class="collapse navbar-collapse navbar-menu">
    <ul class="nav navbar-nav ">
      <li ng-repeat="section in sections" id="nav-home">
        <a href="#{{section.id}}" target="_self">{{section.title}}</a>
      </li>
    </ul> 

and then

 <section ng-repeat="section in sections" id="{{section.id}}">
    <div ng-include="section.view">
    </div>
  </section>

where sections is a list of tuples {title, name, view}.

I tried to put the angular-scroll directives and is not working, but the dependency injection seems ok because I tried .scrollTo() javascript function and it works correctly. Do you think that is possible to use your module for this specific case? Thank you and congratulations for your work.

[Feature Req.] Activate last element when bottom reached

Hi,
I've come across this issue, since the last section of my website (#contact) is to small to get to be the top element when scrolled to the bottom of the page -- thus, does not get activated in my menu bar (adding a higher offset would interfere with the rest of the page).
So, an enhacement would be to always activate the last spy, when the bottom of the page is reached. As far as I know, this is also the default behaviour in the latest bootstrap scrollspy.js. For angular-scroll this behaviour could be activated with a switch or so.

In angular.module('duScroll.spyAPI') you could add

var bottomReached = ($window.scrollY + $window.innerHeight === $document[0].body.scrollHeight);
if (bottomReached && activateLastSpyOnBottom) {
  spy = spies[spies.length-1];
  toBeActive = {
    spy: spy,
    top: spy.getTargetPosition()
  };
} else {
  for(i = 0; i < spies.length; i++) {
  // ... same as before; pick the correct spy for the current position
  }
}

I tested this on Chrome and Firefox and it worked as expected.

iOS - back to top bug

Hello :) Love angluar-scroll tnx!

I Did find a bug in iOS. When you hit the top of Safari's browser to scroll back to top it freaks out angular-scroll. If you start scrolling again manually things work like you would expect but if you hit the top of the browser and are taking back to the top of the page then click an anchor it fails.

iOS7 Safari iPhone/iPad is affected. Chrome seems to be ok tho.

Watch Browserstack screencast: http://www.screencast.com/t/NktJJvQc

Any ideas?

Issues when minified.

Hi,

We are utilizing your code in one of our projects. When published, all of our JS is minified (thanks to bundling and minification in .Net)

What we found was that our JS would error out with an unknown provider.

After picking through all our code we found that the angular-scroll source wasn't really written for minification in mind.

I.E where you have

factory('polyfill', function($window) { ..... });

we changed it to

factory('polyfill', ['$window', function($window) { ....}]);

We did this for all DI methods and it's resolved our issue.

Essentially, because minification changes all the parameter names Angular can't match the new provider parameter name with a known provider.

Not sure if you want to put the fix in your codebase..

How to go in to a specific section from another page?

I have no problem using this directive in a single page, but when 2 pages are present I don't know how to direct them into the specific section.

Example:

app/
├─ index.html
│ ├─ #about
│ ├─ #features
│ └─ #login
└─ login.html
....└─ index.html/#features

It's just redirecting me to the beginning of index.html. Please help.

Scrollspy highlighting with multiple containers

Hi,

thanks for the great work!

I use your directives on a site with multiple containers. The scrolling itself works perfectly but it seems the scrollspy doesn't add the active class properly with multiple containers.

When i set all containers to the same name, scrolling only works in the first container but the highlighting with the active class works.

i also tried changing your container example to use multiple containers and had the same issue.

Wrong active class

When scrolled to page bottom and last container height < window.height, active class is still on previous div, but should be on the last one.

tata

ScrollSpies not readded after routechange #0.5.7

Hi,
i am using the angular-scroll directives in a view, which is included via the "ng-view" directive on my default route, and renders a list of dynamic content. My routes are provided through the $routeProvider.
The directives are working fine until route change events. After back-navigation the scrollspies are not re-added and following a navigation link does not trigger the scrollTo event.
I suppose the corresponding views are not ready when the directives are linked. How can I prevent this behavior?

$scope undefined when using du-scroll-container

I wanted to use this great plugin to scroll the view to the input field that user has selected, so every time an input field is selected, it will be positioned at the top of the page. Anyways, I have run on a strange issue. I have set up controller/view just right , but when I use du-scroll-container like this:

<div class="content" du-scroll-container>
   <input type="text" name="city" ng-model="city" du-active-scroll/>
</div>

The $scope.city is undefined in the controller. Once I remove the 'du-scroll-container' the $scope.city is properly detected in my controller. (du-active-scroll is my personal directive, not affecting this issue).

Do you know how this could be fixed?

Deep linking?

Let's say I'm at #/account and I want to scroll down to Settings and have that url be #/account/settings.

How would you recommend that I do this?

Would it be href="#/account/settings" and id="/account/settings"?

How do I generically turn location updates on? I realize that I'll have to figure out how to tell ui-router to not make a state change, but I think that can be accomplished with $urlRouterProvider.rule

du-scrollspy - stay active until next target element is triggered

Hello,

Would be nice to have such an option.

Use case: using https://github.com/chjj/marked to generate documentation based on markdown, render an anchor id for all heading elements, generate a table of content (TOC) based on heading elements, then place du-scrollspy on the TOC links. Due to heading elements being a single line, active will disappear very fast as user scrolls. Would be nice if TOC links stay active until user scrolls to next anchor.

Karma Test Failing

I'm using angular-scroll in my project, and it's working when I view my site. However my Karma unit test is failing with the falling error:

Module 'duScroll' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.

Has anyone else run into this? I'm sure that I'm including the file in my index.html.

State change then scroll

Do you know of a way to use angular-scroll for state changes or when a new page is loaded? I'd like content to load then scroll to a section of that page

eg. /#!/our-team#staffPicks

Is this functionality present in angular-scroll?

Feature request / question: scrollTo with container in controller

I know that I can use directives to achieve scrolling within another container (for overflow: auto/scroll): du-scroll-container

What I'd like is the ability to do the same thing via the controller code:
parentElement.scrollTo(element) where parentElement would act as the same as the du-scroll-container above.

I want a smooth scroll as soon as the controller is loaded, but not necessarily anything done via the DOM (no clicks, etc)- so I don't want to have to use a directive in order for the scroll to take place.

Is this possible? I tried doing similar things to that, but couldn't get it to work. Thanks.

.scrollTo() not scrolling to element in 0.5.5

Hello, everything works as it should in 0.5.1, but not in 0.5.5. There are no errors, simply not scrolling. Using Angular v1.2.15.

dmanApp.controller('Scroller', function($scope, $location, $document, $anchorScroll) {
$scope.scrollTo = function(id) {
var el = angular.element(document.getElementById(id));
$document.scrollTo(el, 2000);
}
});

Add custom easing support

Great library, but the current animation feels a bit brutal to be honest.

It'd be great to have the option to pass in a custom easing function like the ease-in-out-quad one for example which looks like this (copied for the easing library):

function (x, t, b, c, d) {
  if ((t/=d/2) < 1) return c/2*t*t + b;
  return -c/2 * ((--t)*(t-2) - 1) + b;
}

Any thoughts?

Cancel scroll on mousewheel

After using this in a new project, I thought it may be nice to have an option to allow a cancellation of the animated scroll if the user either uses the mousewheel to scroll, or if they attempt to click/tap on the page.

Not sure if this is possible, or is already on the list. I don't have time to do a PR at the moment, but something to think about perhaps, mainly because animated scrolling can feel a bit "annoying" if you don't have control to stop it.

Simultaneous scrollTo() calls not completing

If any elements are to be scrolled simultaneously using the scrollTo() method only the most recently called method will animate and only it's promise resolved.

I have set up a Plunk here to demonstrate this.

Not being familiar with the animation mechanics makes it hard for me to debug but I have noticed that if you remove the assignment to scrollAnimation and keep it as null then cancelScrollAnimation() is not called and all animations will run but still only the single callback is triggered.

Any ideas?

Doesn't scroll at all when using MEANJS

Hello,

I am developing on the MEANJS platform. I installed your module but I can't seem to get it to work. I followed the instructions and all but for some reason no scrolling occurs.

I dug into the code a bit and the only thing I could find was that the scrollContainerAPI's function getContainerId keeps returning undefined for the id value.

Do you have any idea what the issue is?

Thanks much.

Jumping few pixels sideways when scrolling.

Maybe its my own fault, but i cant seem to find the problem.

Scrolling between two containers on my page "shakes" the page about 10 or 20 pixels to the right, its very noticable.

From what i can see my elements are aligned.

Refresh ScrollSpy after location changes

First, thanks for your work.

When the location change, the DOM change and scrollspy doesn't work.
This patch can resolve the issue:

 return {
    link: function ($scope, $element, $attr) {

    function init() {
      if (!$attr.href || $attr.href.indexOf('#') === -1) return;
      var targetId = $attr.href.replace(/.*(?=#[^\s]+$)/, '').substring(1);
      if(!targetId) return;

      var spy = new Spy(targetId, $element, -($attr.offset ? parseInt($attr.offset, 10) : 0));
      addSpy(spy);

      $scope.$on('$destroy', function() {
        removeSpy(spy);
      });
    }

    init();

    $scope.$on('$locationChangeSuccess', function(next, current) {
        init();
     });
    }
  };

ScrollSpy is not working

I am using Twitter Bootstrap 3.1.1, Angular UI Bootstrap directives 0.10.0 and Angular Scroll.

HTML navigation:

<ul class="nav navbar-nav">
    <li du-scrollspy="burgers" offset="60"><a href="#burgers" du-smooth-scroll offset="60">Burgers</a></li>
    <li du-scrollspy="salads" offset="60"><a href="#salads" du-smooth-scroll offset="60">Salads</a></li>
</ul>

HTML Sections:

<main>
    <section id="burgers">...</section>
    <section id="salads">...</section><
</main>

Scrollspy is not working in version >0.5.0, but everything is ok in 0.4.1

Throws an exception with ng-repeat and filter

Hi,

I'm trying to use it with ng-repeat and filter and it works well, but it thorws an exception when an item is filtered. Here's plunker http://plnkr.co/edit/BCncXn8Y2BWOcREPyGLm?p=preview

Exception:

TypeError: Cannot read property '$id' of undefined
at getContextForScope (http://run.plnkr.co/DLrCmya3BDW2kbOQ/angular-scroll.js:246:25)
at getContextForSpy (http://run.plnkr.co/DLrCmya3BDW2kbOQ/angular-scroll.js:255:14)
at Object.removeSpy (http://run.plnkr.co/DLrCmya3BDW2kbOQ/angular-scroll.js:266:21)
at http://run.plnkr.co/DLrCmya3BDW2kbOQ/angular-scroll.js:436:20
at Scope.$broadcast (https://code.angularjs.org/1.3.0-beta.5/angular.js:12697:28)
at Scope.$destroy (https://code.angularjs.org/1.3.0-beta.5/angular.js:12355:14)
at ngRepeatAction (https://code.angularjs.org/1.3.0-beta.5/angular.js:20609:27)
at Object.$watchCollectionAction as fn
at Scope.$digest (https://code.angularjs.org/1.3.0-beta.5/angular.js:12257:29)
at Scope.$apply (https://code.angularjs.org/1.3.0-beta.5/angular.js:12522:24) angular.js:9784
Event tracked Plunk Save Toolbar undefined undefined

No workie in IE

IE10 not working. Works in compatibility mode.

So, scrollspy works. If I manually scroll, the menu activates where expected.
But clicking on the menu item has not affect in IE10.

Scroll spies do not work when scrolling within an element

If I'm spying on elements residing inside of a scrollable div, I should be able to set spies on them, just like I'm able to call smoothScroll on them using du-scroll-context.

For instance, I should be able to do:

<nav>
   <a href="#section1" du-scrollspy du-smooth-scroll>Section 1</a>
   <a href="#section2" du-scrollspy du-smooth-scroll>Section 2</a>
   <a href="#section3" du-scrollspy du-smooth-scroll>Section 3</a>
</nav>
<div id="scrollable" du-scroll-context>
   <li id="section1">One</li>
   <li id="section2">Two</li>
   <li id="section3">Three</li>
</div>

This would reuse the existing du-scroll-context directive, and extend it to work with du-scrollspy in addition to du-smooth-scroll.

du-scrollspy - better documentation for observation behavior

Currently docs state:

Observes wether the target element is in the viewport and adds an active class if so. Takes optional offset and duration attributes which is passed on to .scrollTo,

Though I'm seeing du-scrollspy becoming active when target element reaches top of viewport, not when it is anywhere in the viewport, is that the case?

One would care if user has a very large viewport and content with multiple anchors is short, seems like none of the du-scrollspy will be triggered.

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.