There is gravity on the moon but its less than the earth.
There is no atmosphere on the moon so the flag must have been still but the photos aren't like that