Download this file

flowtype.js    59 lines (50 with data), 1.7 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
* If you create a derivative, please leave this text intact:
*
* FlowType.JS 1.0
* Copyright (c) 2013, Simple Focus http://simplefocus.com/
*
* FlowType.JS by Simple Focus (http://simplefocus.com/)
* is licensed under the MIT License. Read a copy of the
* license in the LICENSE.txt file or at
* http://choosealicense.com/licenses/mit
*
* Thanks to Giovanni Difeterici (http://www.gdifeterici.com/)
*/
(function($) {
$.fn.flowtype = function(options) {
// Establish default settings/variables
// ====================================
var settings = $.extend({
maximum : 9999,
minimum : 1,
maxFont : 9999,
minFont : 1,
fontRatio : 35,
lineRatio : 1.45
}, options),
// Do the magic math
// =================
changes = function(el) {
var $el = $(el),
elw = $el.width(),
width = elw > settings.maximum ? settings.maximum : elw < settings.minimum ? settings.minimum : elw,
fontBase = width / settings.fontRatio,
fontSize = fontBase > settings.maxFont ? settings.maxFont : fontBase < settings.minFont ? settings.minFont : fontBase;
$el.css({
'font-size' : fontSize + 'px',
'line-height' : fontSize * settings.lineRatio + 'px'
});
};
// Make the magic visible
// ======================
return this.each(function() {
// Context for resize callback
var that = this;
// Set changes on load
changes(this);
// Make changes upon resize
$(window).resize(function(){changes(that);});
});
};
}(jQuery));