Use canvas and some fancy face recognition C code ported to JavaScript to detect how far a user is from the camera
Peter Bengtsson shows how to build a web page able to detect the distance of your face from the screen with JavaScript.
Read more from the source: SitePoint