Skip to content

Instantly share code, notes, and snippets.

Last active January 27, 2018 10:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save abernier/3157389 to your computer and use it in GitHub Desktop.
Baseline detection
alert $('body').baseline()
<!DOCTYPE html>
<meta charset=utf-8>
<script src=""></script>
<script src=""></script>
<script src="" type="text/coffeescript"></script>
<script src="" type="text/coffeescript"></script>
$ = @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>')
setTimeout (-> $container.remove()), 10
$smallA.position().top / $bigA.height()
$.fn.baseline = ->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment