When a current carrying wire is located in a magnetic field, a force is exerted on the wire.
When the current and the magnetic field are perpendicular to each other, the force is given by:
(1)
The force is perpendicular to the plane formed by the current and the magnetic field. Using the right hand rule for our system yields motion towards the top or the bottom of the screen depending on current direction.
Equation 1 details the driving force in the electromagnet. Other forces act upon the system including the inertia of the moving mass, the "back" electromotive force, and possib friction.