jquery - AngularJS - Does scrolling to an element belong in a directive? -


i'm aware dom manipulation belongs in directives rather controllers, i'm hung on whether scrolling element (with jquery's scrolltop) considered dom manipulation and/or should moved directive.

my page dynamically generated (using grails) , small bootstrap dropdown placed on corner of page facilitate scrolling places within lengthy document:

<a ng-click="scrollto('question${ subquestion.id}')"> 

the ${} replaced number when sent client.

my scrollto function within controller rather simple , works:

$scope.scrollto = function(id) {     $('html, body').animate({         scrolltop: $('#' + id).offset().top - 50     }, 1000); }; 

i'm using ui-router , using $uiviewscroll scroll element; seemed more in line angular way need 50px offset because of navigation bar , prefer animation (both don't seem option $uiviewscroll).


questions:

  • does scrolling element have digest consequences true dom manipulation?
  • is scrolling element outside of directive bad practice? if so, why?

  • scrolling runs outside of normal digest cycle, see thread how can hide element when page scrolled?
  • i bad practice since includes references elements in dom, that's me... :-) perhaps can make testing controller bit harder since need handle $.

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -