How can I lock a component to follow the mouse on the Z-axis?

Have a look here, there’s a bunch of examples: