forked from filamentgroup/jQuery-Pixel-Em-Converter
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
scottjehl
committed
Dec 15, 2010
0 parents
commit 3876a44
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title><? echo "Filament Group Lab Example From Page from: $articleTitle"; ?></title> | ||
<link rel="shortcut icon" href="/images/favicon2.ico" type="image/x-icon" /> | ||
<link href="/style/demoPages" media="screen" rel="Stylesheet" type="text/css" /> | ||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> | ||
<script src="../pxem.jQuery.js" type="text/javascript"></script> | ||
<style type="text/css"> | ||
.A,.B,.C,.D { margin: 5px 5px 5px 0; padding: 5px 5px 5px 0; border: 1px solid #333; border-left: 0; position: relative; } | ||
.A { font-size: 2em; width: 90%; } | ||
.B { font-size: 2em; } | ||
.C { font-size: .5em; } | ||
.D { font-size: 5.5em; } | ||
.test { background: #eee; margin: 0; border: 1px dotted #666; padding: 0; line-height: 1em; } | ||
.labeltext { font-size: 12px; white-space: nowrap; position: absolute; top: 10px; right: 10px; line-height: 1 !important; background: url(arrow.gif) 0 50% no-repeat; padding: 0 0 0 15px;} | ||
</style> | ||
<script type="text/javascript"> | ||
$(function(){ | ||
$('div:not(#demoHeader)').each(function(){ | ||
var emval = $(200).toEm({scope: $(this)}); | ||
$('<span class="labeltext"><strong>width:</strong> '+ emval +'</span>') | ||
.prependTo(this); | ||
$('<div class="test"/>') | ||
.width( emval ) | ||
.text('Abc') | ||
.prependTo(this); | ||
|
||
|
||
}); | ||
}); | ||
</script> | ||
</head> | ||
|
||
<body> | ||
|
||
<div class="A"> | ||
<div class="B"> | ||
<div class="C"> | ||
<div class="D"> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*-------------------------------------------------------------------- | ||
* jQuery pixel/em conversion 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) or 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), | ||
scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;"> </div>').appendTo(settings.scope), | ||
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]), | ||
scopeTest = jQuery('<div style="display: none; font-size: 1em; margin: 0; padding:0; height: auto; line-height: 1; border:0;"> </div>').appendTo(settings.scope), | ||
scopeVal = scopeTest.height(); | ||
scopeTest.remove(); | ||
return Math.round(that * scopeVal) + 'px'; | ||
}; |