How to change <div> position relative to element that got clicked

2,226 views
Skip to first unread message

Michael Remijan

unread,
Feb 12, 2013, 8:08:21 AM2/12/13
to ang...@googlegroups.com
I have an ng-click() event which I want to perform two tasks.
1. determine which element on the page was clicked.
2. reposition a <div> relative to the element that was clicked.

I've done some research and it looks like I can use $event to determine which element on the page was clicked. However, what's the "angular way" to reposition the div.  The only way I can think to do it is to use jQuery to get the position of the element clicked on then use jQuery again to change the position of the div.  Functionally this may work, but in terms of how angular does things, I'm guessing reverting to jQuery is not the way to go.  So any suggestions?


ganaraj p r

unread,
Feb 12, 2013, 8:16:01 AM2/12/13
to ang...@googlegroups.com
You can use a combination of ng-click and ng-style to achieve what you are attempting to do..

On ng-click, grab the $event and from the $event you can grab the mouseX and mouseY...

Do some math to convert the mX and mY to the x and y positions of your target div..lets call it targetX and targetY..

Apply these to the target div using ng-style and x,y, position:absolute... 




--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, 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.
 
 



--
Regards,
Ganaraj P R
Reply all
Reply to author
Forward
0 new messages