How is lazy loading done?

How is lazy loading done?

I been looking at many lazy loads scripts. Most show a image html tag with a src to be where a blank image or a image that is basic looking. Then they use  data-src="real_image_here"  which is where the real image location is stored. 

I would like to know how to do lazy loading manually. I want to lazy load all images when they  are in the view port. How can I do this?