Example for the Stackoverflow question: How can I contain D3 JS animation within a container
The balls use a modified version of the D3.js Force Layout. Parts of the code, such as the collision function are taken from Mike Bostock’s example Multi-Foci Force Layout.