The yellow (light) and blue (dark) squares always move together at the same speed, regardless of the background.
The squares appear to move like stepping feet because they contrast so strongly against the black and white stripes.
Detecting motion and speed is particularly strong in your peripheral vision and it’s easier to notice things in your peripheral vision if they contrast strongly. Low contrast patterns generally produce a weaker response in the motion-sensitive parts of your brain.
When the blue (dark) square passes over a white stripe, they contrast strongly against each other and the blue square appears to speed up. As the blue/dark square passes over a black stripe there is low contrast between the two and the square appears to slow down.
Visual information is eventually processed by the visual cortex in your brain, but some pieces of information are processed along separate pathways before reaching your visual cortex.
One pathway is motion-sensitive (and is stimulated first) and the other pathway is colour-sensitive. This colour information is added into the visual cortex movement has been processed.
It all happens so quickly, you don’t notice the lag between each network.