To animate movement (compression) of 3D springs you can use the parameter animation in Inventor.
First model the spring - you can use e.g. the Coil command and its "Revolution and Height" option (the "Coil size" tab). In the Parameters command define a user parameter which will specify the spring height. Set an appropriate start or end value for it.
Use this user parameter to define the height (length) of your coil.
Save the model and switch to the Inventor Studio module. In the "Animation Timeline" function, set the requested length (timespan) of the animation. In the "Parameter Favorites" check the Height (Length) parameter.
Now start the "Animate Parameters" command using your user parameter and the action limits set the requested animation. Then Render the animation.
You can also use the pre-prepared spring block -
Spring cut (IPT) from the CAD Block Library.