Overview
The Fancy Letter Plugin lets you prettify your web page by styling the first letter of any element while keeping the HTML markup clean and readable by both human and machine.
If you like this plugin and you're feeling generous, perhaps you'd also like to visit my amazon.com wish list?
Quick Start Guide
<head>
of your document. After these scripts are referenced, you can reference a custom
script file to add your fancy letters (preferred) or enter the script directly in the
<head>
(shown below).
<script src="jquery.js" type="text/javascript"></script>
<script src="jquery.fancyletter.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function() {
// simple example wraps the first letter of
$('div.content p').fancyletter();
});
</script>
Fancy letters are wrapped in a span tag. Each span is given two classes: a common class ("fancy-letter" by default) and a "letter" class.
For example, after applying the .fancyletter()
method to:
<p>This paragraph</p>
it might look like this:
<p><span class="fancy-letter ltr-t">T</span>his paragraph</p>
.
See API / Options for more ways to customize the behavior and appearance of the expander.
This sentence begins with a fancy letter, produced by the code below:
$('#demo p:first').fancyletter();
And this sentence begins with a different fancy letter, produced by this code:
$('#demo p:eq(1)').fancyletter({commonClass: 'scarlet-letter'});
“D”ieter Steffman has a lot of beautiful fonts like this one (Sentinal). To show it, I used the following code, along with an @font-face declaration. View source to see the styles applied.
$('#demo .steffman').fancyletter({commonClass: 'ds'});
characters
option. It takes a
string that is interpreted as a regular expression.
$('#demo-divs > div').fancyletter({ltrClassPrefix: 'bg-', characters: '[A-S]'});
Fancy Letter Plugin API / Options
The Fancy Letter Plugin API provides a single method with a few options.
fancyletter(options)
- Wraps a span element (with classes) around the first letter of all elements matched by the jQuery selector.
$.fn.fancyletter.defaults = {
commonClass: 'fancy-letter',
ltrClassPrefix: 'ltr-',
characters: '[a-zA-Z0-9]',
groupPunctuation: true,
punctuationClass: 'punct',
punctuationLeft: {
'"': 'dquo',
"'": 'squo',
'“': 'ldquo',
'‘': 'lsquo',
'«': 'laquo',
'‹': 'lsaquo',
'(': 'lparen'
},
punctuationRight: {
'"': 'dquo',
"'": 'squo',
'”': 'rdquo',
'’': 'rsquo',
'»': 'raquo',
'›': 'rsaquo',
')': 'rparen'
}
};
Download
The Fancy Letter Plugin is available at: github.com/kswedberg/jquery-fancyletter.Support
If you discover a bug with the Fancy Letter Plugin, please submit a report at github.com/kswedberg/jquery-fancyletter/issues.