Baseline detection
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
alert $('body').baseline() |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset=utf-8> | |
<title></title> | |
<script src="http://code.jquery.com/jquery-latest.min.js"></script> | |
<script src="https://cdnjs.cloudflare.com/ajax/libs/coffee-script/1.12.8/coffee-script.js"></script> | |
<script src="jquery.baseline.coffee" type="text/coffeescript"></script> | |
<script src="index.coffee" type="text/coffeescript"></script> | |
</head> | |
<body> | |
</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
$ = @jQuery ? require 'jQuery' | |
detectBaseline = (el = 'body') -> | |
### | |
+----+ ^ | |
| +-+| | baseline | |
|.|A|| v | |
| +-+| | |
+----+ | |
### | |
$container = $('<div style="visibility:hidden;"/>') | |
$smallA = $('<span style="font-size:0;">A</span>') | |
$bigA = $('<span style="font-size:999px;">A</span>') | |
$container | |
.append($smallA).append($bigA) | |
.appendTo(el); | |
setTimeout (-> $container.remove()), 10 | |
$smallA.position().top / $bigA.height() | |
$.fn.baseline = -> | |
detectBaseline(@get(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://bl.ocks.org/3157389