My motivation for tracking text size changes is to dynamically change the height (or width) of elements, so the scroll bar of the browser window is not required on the entire page. Usually, when you do this, you respond to a resize event, but changes in font size can also affect your calculations. I don't care what the actual font size is, I just need to know when it will change.
Here is the jQuery code I'm using. This is similar to the solution proposed by bobince. I have a resize function that will update the height of a div, etc.
$(window).resize(resize); // update when user resizes the window. $("body").append("<p id='textSizeReference' style='display:none;padding:0'>T</p>"); var refTextHeight = $("#textSizeReference").height(); setInterval(function() { var h = $("#textSizeReference").height(); if (h != refTextHeight) { refTextHeight = h; resize(); // update when user changes text size } }, 500);
If this is an ajax application that is polled for changes to location.hash, you can use the same polling function to resize the text.
John snyders
source share