How to watch (monitor) the size (width/height) of a dom element?

2,457 views
Skip to first unread message

Bernd Wessels

unread,
Mar 7, 2013, 3:06:23 AM3/7/13
to ang...@googlegroups.com
Hello

What is the best way to be triggered whenever the width and height of a dom element changes?

Cheers

Bernd

Saurabh Nanda

unread,
Mar 7, 2013, 3:29:49 AM3/7/13
to ang...@googlegroups.com
I would suggest NOT going down that route. Instead move a step higher in the abstraction chain and trap the event which triggers the heigh/width change. 

What's your use-case?

Saurabh.

Bernd Wessels

unread,
Mar 7, 2013, 5:21:26 AM3/7/13
to ang...@googlegroups.com
Simplest Usecase is: Lots of elements are bound to the model of my controller. When they change I need to update the elements positions according to their contents changed dimensions.

Saurabh Nanda

unread,
Mar 7, 2013, 5:29:33 AM3/7/13
to ang...@googlegroups.com
Are you trying to implement a Pinterest kind of layout, eg. http://galleria.io/themes/folio/ ?

I'd recommend using a custom directive which watches a variable that is shared between the directive & the controller, eg. scope.reposition. Whenever you change the model and would like to reposition the DOM elements, simply increment the value of scope.reposition.

The other approach would be to use $timeout and trigger the reposition every X seconds.

Any other suggestions?

Saurabh.

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/U_e5pFHpdH4/unsubscribe?hl=en-US.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
http://www.saurabhnanda.com
Reply all
Reply to author
Forward
0 new messages