Is it possible to achieve effect like this?
I know how to do it static way, but I would like to have it like this when I move the layer with text or rectangle also
This kind of works.
Create your box, colored text, and a copy of the text with the same color as the background
Place color text at the bottom, and make the background color (white) text clipped to the box. Your Layers panel will look like this.
Demo
Moving just the box will work as well. You just have to make sure to edit both text layers if you make an adjustment.