What I noticed is that the size changes because:
1. When you just reboot. The function runs only once.
2. But when you resize, the function runs twice and resizes the font, because the recalculation is based on the new height. Most importantly, resizing is not calculated correctly innerheight
See this:
function foo(jQuery ){ var container = $(".box"); var containerHeight = $(".box").innerHeight(true).toFixed(2); var neededSize = (containerHeight/100*40.32).toFixed(2); alert(containerHeight ); container.css("font-size", neededSize + "px"); } $(window).resize(foo); $(document).ready(foo);
The resizing method is not reliable. The code in the resize handler should never rely on the number of calls to the handler. Depending on the implementation, resizing events can be sent continuously as they are resized (typical behavior in Internet Explorer and WebKit browsers such as Safari and Chrome), or only once at the end of the resize operation (typical behavior in some other browsers, such as Opera).
Yo yo source share