Such an episode is called a vasovagal reaction. It is thought to be a malfunction of a body system that is meant to regulate blood circulation, such as when you change position from sitting to standing.
In certain circumstances, which may include seeing blood or having your eyes examined, your involuntary nervous system behaves as if you were lying down, when actually you are sitting or standing up. At first, your heart usually races because of anxiety. Then your pulse rate slows precipitously and blood vessels to your legs dilate, or widen. As a result, the blood supply increases to your legs and lessens to your head. Your brain runs short of oxygen, and you faint.
You might look away when your blood is being drawn, or you could lie down during the procedure. As mentioned, when a vasovagal reaction is about to begin, you can often recognize the warning signs. So there is usually time to take action before you faint. Many doctors recommend that you lie down and prop your legs up against a chair or a wall. This prevents your blood from draining into your legs, and thus you may be able to prevent the reaction from running its full course. Within just a few minutes, you will probably feel better.