javascript - AngularJS - Finding width of changing DOM elements -



javascript - AngularJS - Finding width of changing DOM elements -

i sense of angular questions inquire me missing incredibly dumb, let's hope too.

i'm building directive command scrolling of wide list of thumbnails. in jquery, had working perfectly, jquery wasn't comfortable grabbing dynamically loaded list angular, i'm rewriting code. basically, i've got gallery exists in ng-repeat:

<div id="gallery"> <ul id="gallery_img"> <li class="thumb" ng-repeat="image in thumbnails"> <img ng-src="{{image.thumbnail}}" alt="{{image.description}}" /> </li> </ul> </div>

and when click on further-down buttons,

<slider class="mover" style="left:0;">&laquo;</slider> <slider class="mover" style="right:0;">&raquo;</slider>

the list supposed animate/slide backwards , forwards width of image in "0" position. basically, grabs width, adds width ul left position. super simple, right?

here's directive i've got controlling motion @ moment:

app.directive('slider', function() { //to reuse, replace "#gallery_img" whatever want homecoming { restrict: 'e', link: function(scope, element, attrs){ var tomove = angular.element('#gallery_img'); var imagewidth; var imagenumber = 1; element.bind('mousedown', function(){ tomove.css({left: '-=200'}); console.log(tomove.children([imagenumber]).width()); console.log(imagenumber); imagenumber +=1; }); } } });

i added in console.log details, see widths i'm getting. imagenumber changing; each time click next or previous, number goes one. width i'm getting, though, first image in each set; i've got several galleries, no matter how many times click "next," gallery 1 ever give me "566," gallery 2 "433", gallery 3 "521." each image of exclusively different size, so... why giving me width of first image?

e: here's plnkr of i'm talking about: http://plnkr.co/edit/nlg4oksngvytgemg9uov

in next code:

tomove.children([imagenumber]).width()

you passing imagenumber children function. children function accepts optional selector, not indexer. in case homecoming jquery object containing li , phone call width() homecoming width of first.

instead pass indexer children function returns , go there (dividing clarity):

var children = tomove.children() var width = $(children[imagenumber]).width(); console.log(width);

or:

var width = tomove.children().eq(imagenumber).width(); console.log(width);

javascript html angularjs

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -