Created
May 17, 2013 10:13
-
-
Save syxc/5598238 to your computer and use it in GitHub Desktop.
Zepto.FitText.js
This file contains hidden or 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
| /*global jQuery */ | |
| /*! | |
| * FitText.js 1.1 | |
| * | |
| * Copyright 2011, Dave Rupert http://daverupert.com | |
| * Released under the WTFPL license | |
| * http://sam.zoy.org/wtfpl/ | |
| * | |
| * Date: Thu May 05 14:23:00 2011 -0600 | |
| */ | |
| (function ($) { | |
| $.fn.fitText = function (kompressor, options) { | |
| // Setup options | |
| var compressor = kompressor || 1, | |
| settings = $.extend({ | |
| 'minFontSize': Number.NEGATIVE_INFINITY, | |
| 'maxFontSize': Number.POSITIVE_INFINITY | |
| }, options); | |
| return this.each(function () { | |
| // Store the object | |
| var $this = $(this); | |
| // Resizer() resizes items based on the object width divided by the compressor * 10 | |
| var resizer = function () { | |
| $this.css('font-size', Math.max(Math.min($this.width() / (compressor * 10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize))); | |
| }; | |
| // Call once to set. | |
| resizer(); | |
| // Call on resize. Opera debounces their resize by default. | |
| $(window).on('resize', resizer); | |
| }); | |
| }; | |
| })(Zepto); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use?
http://jsfiddle.net/aL26a/