I'm trying to produce a photo slider that is dynamically sized according to the viewport size, but maintains a 4:3 ratio regardless of viewport dimensions.
The page I'm working on is here: http://steph-morris.com/thenovel_III.html
Width is currently being calculated by grabbing the viewport width and subtracting the size of the menu bars, like so:
$(document).ready(function(){
var height = $(window).height(), width = $(window).width();
$('img').css('width', (width - (281+(height*0.32))) + 'px');
});
(Where one menu is a known width of 281px and the other menu is calculated as height*0.32).
I need to calculate height in relation to width in a 4:3 ratio.
I am brand new to jQuery maths and haven't been able to get a working nested equation that does something like
$('img').css('height', ((width - (281+(height*0.32))*thecorrectratio) + 'px');
Also, this is not an efficient approach- I should be storing the outcome of the 'width' calculation I think and calculating it more as
$('img').css('height', (widthvalue*thecorrectratio) + 'px');
But I also don't know how to do that with jQuery.
So I would really appreciate any assistance with (a) how to write a good nested equation to work out the value of 'height', or (b) how to save the outcome of the 'width' equation so that it can be used again, and obviously (c) the correct way to calculate a 4:3 ratio.