- Read the original blog post
- Play around on the demo
- Watch the video
Or use bower: bower install bigtext
- jQuery
- A block level parent element. BigText will force all children to be block level as well.
BigText works best on browsers that support subpixel font scaling. In order to best serve sizes to all browsers, BigText will adjust word-spacing
as well as font-size
.
<div id="bigtext">
<span>BIGTEXT</span>
<span>Makes Text Big</span>
</div>
<script>
$('#bigtext').bigtext();
</script>
Use display: inline
children (like a span
) so the text will flow correctly if BigText doesn’t run.
<div id="bigtext">
<span>BIGTEXT</span>
<span>Makes Text Big</span>
</div>
<script>
// Only BigText on “new-ish” browsers
if( 'querySelectorAll' in document ) {
$('#bigtext').bigtext();
}
</script>
<ol id="bigtext">
<li>BIGTEXT</li>
<li>Makes Text Big</li>
</ol>
<script>
$('#bigtext').bigtext();
</script>
<div id="bigtext">
<p>BIGTEXT</p>
<p>Makes Text Big</p>
</div>
<script>
$('#bigtext').bigtext({
childSelector: '> p'
});
</script>
<ol id="bigtext">
<li>BIGTEXT</li>
<li class="bigtext-exempt">Makes Text Big</li>
</ol>
<script>
$('#bigtext').bigtext();
</script>
<ol id="bigtext">
<li>
<span style="font-family: sans-serif">BIG</span>
<span style="font-family: serif">TEXT</span>
</li>
<li>Makes Text Big</li>
</ol>
<script>
$('#bigtext').bigtext();
</script>
Works also with letter-spacing
, word-spacing
, and text-transform
.
Warning: a known issue exists with the Google/TypeKit font loader in WebKit.
<div id="bigtext">
<span>BIGTEXT</span>
<span>Makes Text Big</span>
</div>
<script src="//ajax.googleapis.com/ajax/libs/webfont/1/webfont.js"></script>
<script>
$(function() {
WebFont.load({
custom: {
families: ['LeagueGothicRegular'], // font-family name
urls : ['css/fonts/league-gothic/stylesheet.css'] // URL to css
},
active: function() {
$('#bigtext').bigtext();
}
});
});
</script>
<div id="bigtext">
<span>BIG</span><!-- the shorter the line, the larger the size required -->
</div>
<script>
$('#bigtext').bigtext({
maxfontsize: 60 // default is 528 (in px)
});
</script>
<div id="bigtext">
<span>This is a super long line that will probably be resized to epically small proportions. We need a minimum font size!</span>
</div>
<script>
$('#bigtext').bigtext({
minfontsize: 16 // default is null
});
</script>
See Paravel's FitText plugin. Curious how the two plugins compare? I've written a full comparison between FitText and BigText.
As of 0.1.8, BigText implements its own debounced resize event.
BigText uses an off-canvas detached node to improve performance when sizing. Setting DEBUG_MODE
to true will leave this detached node on the canvas for visual inspection for problem resolution.
BigText.DEBUG_MODE = true;
The starting font-size must be small enough to guarantee that each individual line is not wrapping pre-BigText. If the line is too long, BigText will not size it correctly.
v0.1.0
Initial releasev0.1.1
Added line exempt feature.v0.1.2
Responsive BigText resizes with media queries and resize events (optionally debounced).v0.1.3
v0.1.4
on2013-08-24
Numerous bug fixes, improved accuracy, adds debug mode.v0.1.5
on2013-10-14
BigText uses all children by default (#40)v0.1.6
Various bug fixes.v0.1.7
Various bug fixes.v0.1.8
Various bug fixes.v1.0.1
on2017-06-01
Release.v1.1.0
on2017-09-20
Added breakpoint and childwrap feature.v1.1.1
on2017-09-20
Fixed package versionv1.1.2
on2017-09-20
Removed static line-height style of bigtext stylesv1.1.3
on2017-09-26
Tweaked size calculation to avoid text truncation.v1.1.4
on2017-10-02
Replaced bind/unbind with off/on for compatibility with jquery3
Run these commands:
npm install
bower install
grunt
Rather than one giant Gruntfile.js
, this project is using a modular Grunt setup. Each individual grunt configuration option key has its own file located in grunt/config-lib/
(readonly upstream configs, do not modify these directly) or grunt/config/
(project specific configs). You may use the same key in both directories, the objects are smartly combined using Lo-Dash merge.
For concatenation in the previous Gruntfile setup, you’d add another key to the giant object passed into grunt.initConfig
like this: grunt.initConfig({ concat: { /* YOUR CONFIG */ } });
. In the new configuration, you’ll create a grunt/config/concat.js
with module.exports = { /* YOUR CONFIG */ };
.
Plugin has been modified to support different min max font-sizes dependend on breakpoints.
New optional parameter for configuration are:
- breakpointFontsizes
- childWrap
DEFAULT OPTIONS:
{
// default font sizes
minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
// breakpoints - if viewport provides AT LEST <key>px space
// use defined min- and max-fontsize for that breakpoint
breakpointFontsizes: {},
childSelector: '',
childWrap: '<span></span>',
resize: true
}
Configure breakpoint dependend minfontsize and maxfontsize
minfontsize: BigText.DEFAULT_MIN_FONT_SIZE_PX,
maxfontsize: BigText.DEFAULT_MAX_FONT_SIZE_PX,
breakpointFontsizes: {
'768': {
minfontsize: 35,
maxfontsize: 80
},
'1024': {
minfontsize: 35,
maxfontsize: 150,
}
}
Description:
Viewport width | Comment |
---|---|
0px - 767px | default font min, max sizes will be used |
768px - 1023px | min, max font sizes of breakpoint 768 will be used |
1024px - ZZZpx | min, max font sizes of breakpoint 1024 will be used |
Plugin works only if the text is wrap by a child element of the bigtext selector. If no wrapping element can be found - the plugin provides wrapper element automatically. Option can be changed to use another wrapper.