1 /*--------------------------------------------------------------------
2 * jQuery pixel/em conversion plugins: toEm() and toPx()
3 * by Scott Jehl (scott@filamentgroup.com), http://www.filamentgroup.com
4 * Copyright (c) Filament Group
5 * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) or GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
6 * Article: http://www.filamentgroup.com/lab/update_jquery_plugin_for_retaining_scalable_interfaces_with_pixel_to_em_con/
8 scope: string or jQuery selector for font-size scoping
9 * Usage Example: $(myPixelValue).toEm(); or $(myEmValue).toPx();
10 --------------------------------------------------------------------*/
12 $.fn.toEm = function(settings){
13 settings = jQuery.extend({
16 var that = parseInt(this[0],10),
17 scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;"> </div>').appendTo(settings.scope),
18 scopeVal = scopeTest.height();
20 return (that / scopeVal).toFixed(8) + 'em';
24 $.fn.toPx = function(settings){
25 settings = jQuery.extend({
28 var that = parseFloat(this[0]),
29 scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;"> </div>').appendTo(settings.scope),
30 scopeVal = scopeTest.height();
32 return Math.round(that * scopeVal) + 'px';