开发者

jquery - adjust all font sizes where they are declared?

开发者 https://www.devze.com 2023-01-30 07:25 出处:网络
Im detecting if the user has Calibri installed: $(document).ready(function() { var cWidth = $(\'.calibri\').width();

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消