The motion of particles in a stellarator magnetic field is investigated. A new approach is demonstrated by discussing the nonlinear oscillator problem for which it is possible to evaluate explicitly the change of the adiabatic invariant due to the crossing of the separatrix. It is found that in the case of the 'fast' crossing, which occurs when the particles cross the separatrix far from the X-point, this change is of the order of ln (), where is a perturbation parameter. Also found is the spectrum of invariants for the 'slow' crossing, which occurs when the particles cross the separatrix near the X-point. A regular procedure is proposed for deriving the invariant for locally trapped particles, with the finite rotational transform per period being taken into account. The trapping probability in stellarators is also calculated