There is a library that gives the effect you are trying to achieve.
Aos library
Otherwise, if You do not to use any library then this can be done by javascript.