It's because of the fitmode
. The jQuery UI position utility has an intelligent collision detection system that will position the element based on its proximity to the edges of its container, so once it gets too close to one edge, it will flip the position (which is why you see the inversion) to try and fit it better
See the collision
option in the API docs