The force of gravity mainly depends upon mass and distance.Although sun is bigger than earth moon is closer to the earth.The law of inertia (Newton's first law) predicts that :If there was no gravitational force than the moon would have gone in a straight line at a constant speed.It is deflected from a straight line path by the force of gravity.This causes moon to fall a little bit towards the earth at the same time it moves to one side.