This is probably the commonest cause of losing consciousness.
The main reason is that there is not enough blood flowing to the brain. A very good website to look at is www.stars.org.uk.

Episodes usually occur in children in their teenage years and often there is a family history. A good example would be a child who has been standing for  a while. The blood pools in their legs and he/she feels dizzy. When they fall to the ground, the blood flow to the brain is re established as the brain is at the same level as the heart in that posture. They then regain consciousness.

It can happen with exercise after a good lunch. It can also happen on seeing blood in some children. The pain or fright stimulates the vagus nerve. The vagus nerve supplies the heart. This slows down the heart rate. The blood supply to the brain is compromised and the person loses consciousness. This is called vasovagal syncope.

Syncope can happen while suddenly getting up from sitting or lying position, in a crowded room, passing urine ( Micturitional syncope), combing - Combing syncope, etc. )
The importance of identifying these conditions is to prevent unnecessary investigations and treatment.
I strongly advise a consultation with a Paediatric Neurologist if there is loss of consciousness to rule out Syncope.

All children diagnosed with Syncope should have an ECG. 
If Syncope happens with exercise, Cardiology review to rule out arrhythmia is essential.