Im detecting if the user has Calibri installed:
$(document).ready(function() {
var cWidth = $('.calibri').width();
var aWidth = $('.arial').width();
if (cWidth == aWidth){
//No Cal开发者_Go百科ibri installed
}
});
How would I find any classes that define the font-size and then reduce them by say 20%?
You should use CSS:
body {font-size:80%}
Trying to control fonts precisely on the client is a fool's game; You will spend a lot of time trying only to eventually fail. If some unholy hack existed to force your exact font, what real value would it be? Web pages are documents, not movie posters. Set your font as a generic family and move on.
body {font-family:sans-serif}
Assuming your javascript linked is working to this point, completing it is a matter of setting the sizes I believe (if i understood correctly), here is what should work:
$(document).ready(function() {
var cWidth = $('.calibri').width();
var aWidth = $('.arial').width();
if (cWidth == aWidth){
$('div, span, input, p, h1, h2 ...etc ').each(function(i) { /* This is suspect, it needs to
select all tags*/
if($(this).css('font-size').length) {
var currentSize = parseInt($(this).css('font-size'));
var newSize = currentSize * .8;
$(this).css('font-size', newSize + " <unit> ");
}
});
}
});
This is questionable, but might get you closer to what you are looking for.
edit, major brain fart, you have to check for font-size
after getting the element. This still might not be perfect (haven't been able to test it), but the idea is you need to check for a return from $(this).css('font-size')
Hope this helps. The more I think about it, its a pretty kludgy thing to try to do.
精彩评论