Created
April 13, 2015 16:47
-
-
Save abbotto/289ada81e2632bff40b0 to your computer and use it in GitHub Desktop.
Meta JS: Swap Positions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <b>Positioning</b><hr> | |
| <div style='height: 250px'> | |
| <div id='anchor' style='border:1px solid #000; width: 120px; height: 100px;'>Anchor</div> | |
| <br> | |
| <div id='object' style='background: blue; color: white; border:1px solid #000; width: 120px; height: 100px;'>Object</div><br> | |
| </div> | |
| <button id='reposition'>Swap positions</button> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $('#reposition').on('click', function(){ | |
| var anchor_offset = $('#anchor').get('offset'); | |
| var anchor_height = $('#anchor').get('outerHeight'); | |
| var anchor_top = anchor_offset['top']; | |
| var anchor_width = $('#anchor').get('outerWidth'); | |
| var anchor_left = anchor_offset['left']; | |
| var object_offset = $('#object').get('offset'); | |
| var object_height = $('#object').get('outerHeight'); | |
| var object_top = object_offset['top']; | |
| var object_width = $('#object').get('outerWidth'); | |
| var object_left = object_offset['left']; | |
| $('#object').add('css', {'position':'absolute', 'top':anchor_top+'px', 'left':anchor_left+'px'}); | |
| $('#anchor').add('css', {'position':'absolute', 'top':object_top+'px', 'left':object_left+'px'}); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment