Skip to content
Browse files

'init'

  • Loading branch information...
0 parents commit ddf81a8950ade362c63923c5eb52b385529ced1a John Antoni Griffiths committed Jan 20, 2010
Showing with 43 additions and 0 deletions.
  1. +10 −0 README.txt
  2. +33 −0 pxem.jQuery.js
10 README.txt
@@ -0,0 +1,10 @@
+/*--------------------------------------------------------------------
+ * jQuery plugins: toEm() and toPx()
+ * by Scott Jehl (scott@filamentgroup.com), http://www.filamentgroup.com
+ * Copyright (c) Filament Group
+ * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
+ * Article: http://www.filamentgroup.com/lab/update_jquery_plugin_for_retaining_scalable_interfaces_with_pixel_to_em_con/
+ * Options:
+ scope: string or jQuery selector for font-size scoping
+ * Usage Example: $(myPixelValue).toEm(); or $(myEmValue).toPx();
+--------------------------------------------------------------------*/
33 pxem.jQuery.js
@@ -0,0 +1,33 @@
+/*--------------------------------------------------------------------
+ * jQuery plugins: toEm() and toPx()
+ * by Scott Jehl (scott@filamentgroup.com), http://www.filamentgroup.com
+ * Copyright (c) Filament Group
+ * Dual licensed under the MIT (filamentgroup.com/examples/mit-license.txt) and GPL (filamentgroup.com/examples/gpl-license.txt) licenses.
+ * Article: http://www.filamentgroup.com/lab/update_jquery_plugin_for_retaining_scalable_interfaces_with_pixel_to_em_con/
+ * Options:
+ scope: string or jQuery selector for font-size scoping
+ * Usage Example: $(myPixelValue).toEm(); or $(myEmValue).toPx();
+--------------------------------------------------------------------*/
+
+$.fn.toEm = function(settings){
+ settings = jQuery.extend({
+ scope: 'body'
+ }, settings);
+ var that = parseInt(this[0],10);
+ var scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope);
+ var scopeVal = scopeTest.height();
+ scopeTest.remove();
+ return (that / scopeVal).toFixed(8) + 'em';
+};
+
+
+$.fn.toPx = function(settings){
+ settings = jQuery.extend({
+ scope: 'body'
+ }, settings);
+ var that = parseFloat(this[0]);
+ var scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;">&nbsp;</div>').appendTo(settings.scope);
+ var scopeVal = scopeTest.height();
+ scopeTest.remove();
+ return Math.round(that * scopeVal) + 'px';
+};

0 comments on commit ddf81a8

Please sign in to comment.
Something went wrong with that request. Please try again.