I need a simple jquery solution to add a background image to my page filling it entirely, but keeping the aspect ratio and vertical and horizontal centered position.
there are several plugins out here but I don't want to use any plugin.
thanks in advance.
Or you could use the CSS property :
This will scale the image, while preserving its intrinsic aspect ratio (if any), to the smallest size such that both its width and its height can completely cover the background positioning area.
You can control how your image is aligned within the viewport by using the
background-position
propertyThis code will do what you want..
Set your HTML like this
and your CSS like
Demo at http://jsfiddle.net/gaby/3YLQf/