<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cool Javascripts &#187; font size controller</title>
	<atom:link href="http://cool-javascripts.com/tag/font-size-controller/feed" rel="self" type="application/rss+xml" />
	<link>http://cool-javascripts.com</link>
	<description>The best javascripts for your site</description>
	<lastBuildDate>Tue, 22 Mar 2011 14:35:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Building a reusabe font size controller interface using jQuery</title>
		<link>http://cool-javascripts.com/jquery/building-a-reusabe-font-size-controller-interface-using-jquery.html</link>
		<comments>http://cool-javascripts.com/jquery/building-a-reusabe-font-size-controller-interface-using-jquery.html#comments</comments>
		<pubDate>Wed, 14 Jan 2009 13:57:34 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[change font size]]></category>
		<category><![CDATA[font]]></category>
		<category><![CDATA[font size controller]]></category>

		<guid isPermaLink="false">http://cool-javascripts.com/jquery/building-a-reusabe-font-size-controller-interface-using-jquery.html</guid>
		<description><![CDATA[Most of the web2.0 design allows the user to change the font size of the main content area. This is indeed a good usability. So I thought, I should contribute something here. The result is a small jQuery code which can be used to generate a font size changer interface. Only thing you need to [...]


Related posts:<ol><li><a href='http://cool-javascripts.com/jquery/vertical-alignment-of-contents-inside-an-element-using-jquery.html' rel='bookmark' title='Permanent Link: Vertical alignment of contents inside an element using jQuery'>Vertical alignment of contents inside an element using jQuery</a> <small>One of the old problems! Vertical alignment of contents inside...</small></li><li><a href='http://cool-javascripts.com/jquery/add-icons-to-your-links-automatically-using-jquery-css.html' rel='bookmark' title='Permanent Link: Add icons to your links automatically using jQuery &#038; CSS'>Add icons to your links automatically using jQuery &#038; CSS</a> <small>You want to show a particular icon to a particular...</small></li><li><a href='http://cool-javascripts.com/effects/make-curved-corners-with-jquery-corner-plugin.html' rel='bookmark' title='Permanent Link: Make curved corners with jQuery Corner plugin'>Make curved corners with jQuery Corner plugin</a> <small>If you want a curved edge for your element, the...</small></li></ol>

Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.]]></description>
			<content:encoded><![CDATA[<p>Most of the web2.0 design allows the user to change the font size of the main content area. This is indeed a good usability. So I thought, I should contribute something here. The result is a small jQuery code which can be used to generate a font size changer interface. </p>
<p><img src="http://cool-javascripts.com/wp-content/uploads/2009/01/fontsize-controller.jpg" /></p>
<p>Only thing you need to make is a holder element for the controller and then call the function like</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">fontSize<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#holder&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;#content&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span>;
<span style="color: #006600; font-style: italic;">// holder is the id of the element where the font size controller interface will be shown</span>
<span style="color: #006600; font-style: italic;">// content is the id of the element where the font size changes will take place.</span>
<span style="color: #006600; font-style: italic;">// The next three arguments are Minimum font size, Default font size and Maximum font size respectively</span></pre></div></div>

<p>Yes, all done and it will automatically generate all required buttons. It also supports jquery cookie plugin. So when you open the page again, the preferred font size will be restored automatically. (Cookie plugin is not required, but recommended)</p>
<p>After the function is called, the controllers will be generated in the specified area like the following.</p>
<p><img src="http://cool-javascripts.com/wp-content/uploads/2009/01/jquery-automatic-font-size-controller-cool-javascriptscom-ultimate-javascript-resources.jpg" /></p>
<h3>Advantages</h3>
<ul>
<li>Small size, built on jQuery</li>
<li>Fully skinnable using css</li>
<li>Multiple interface can be used in the same page for two different content areas</li>
<li>Support jQuery Cookie plugin for remembering the preferred font size</li>
<li>Very easy to use</li>
</ul>
<p><span id="more-127"></span></p>
<h3>The logic</h3>
<ul>
<li>The function will be called with the holder element and target element with default, maximum and minimum font size</li>
<li>Create three elements for decreasing, default and increasing font size </li>
<li>Style the elements using CSS so that it will be fully skinnable</li>
<li>Upon clicking read the current font size for the target and calculate the new font size. Then apply it to target element</li>
<li>Save the modified font size value to cookie, so that the preferred font size can be saved and restored</li>
</ul>
<h3>The CSS</h3>
<p>We need some buttons for the backgrounds and the best places to search is <a href="http://www.iconlook.com" target="_blank">Icon look</a>, <a href="http://www.iconfinder.net" target="_blank">Icon Finder</a> and <a href="http://www.iconlet.com" target="_blank">Icon Let</a> as usual. I found the above images, but you can use another or design yours.</p>
<p>Now we need to style the elements. Mainly we need 5 styles &#8211; Button for smaller font, default font and larger font. We need two more styles for the disabled state of buttons. (If current font size is the minimum or maximum allowed, we need to show a disabled state).</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;">&nbsp;
&nbsp;
<span style="color: #6666ff;">.smallFont</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>; <span style="color: #808080; font-style: italic;">/*for making it look nice in FF */</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/font-down.png</span><span style="color: #00AA00;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999px</span>;
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.defaultFont</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #808080; font-style: italic;">/*if you want to hide the default font button, use display:none */</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/font-default.png</span><span style="color: #00AA00;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999px</span>;
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.largeFont</span> <span style="color: #00AA00;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span><span style="color: #ff0000; font-style: italic;">images/font-up.png</span><span style="color: #00AA00;">&#41;</span>;
	<span style="color: #000000; font-weight: bold;">outline</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">none</span>;
	<span style="color: #000000; font-weight: bold;">text-indent</span><span style="color: #00AA00;">:</span> <span style="color: #933;">-9999px</span>;
	<span style="color: #000000; font-weight: bold;">display</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">block</span>;
	<span style="color: #000000; font-weight: bold;">float</span><span style="color: #00AA00;">:</span> <span style="color: #000000; font-weight: bold;">left</span>;
	<span style="color: #000000; font-weight: bold;">width</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
	<span style="color: #000000; font-weight: bold;">height</span><span style="color: #00AA00;">:</span> <span style="color: #933;">32px</span>;
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.ldisabled</span><span style="color: #00AA00;">,</span><span style="color: #6666ff;">.sdisabled</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #808080; font-style: italic;">/*Styles for disabled buttons*/</span>
	opacity<span style="color: #00AA00;">:</span> <span style="color: #cc66cc;">0.3</span>;
	-ms-filter<span style="color: #00AA00;">:</span> <span style="color: #ff0000;">&quot;progid:DXImageTransform.Microsoft.Alpha(Opacity=30)&quot;</span>;
	<span style="color: #808080; font-style: italic;">/*This is for IE8 */</span>
	filter<span style="color: #00AA00;">:</span> alpha<span style="color: #00AA00;">&#40;</span>opacity <span style="color: #00AA00;">=</span> <span style="color: #cc66cc;">30</span><span style="color: #00AA00;">&#41;</span>;
<span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>As you can see I&#8217;ve used three background images for the three buttons. Need to set the display:block property as the buttons are of 32px height. I could have optimized the css more by applying common styles to elements. For eg: For the three styles only background is different, so it could&#8217;ve declared like the following.</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"> <span style="color: #6666ff;">.smallFont</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.defaultFont</span><span style="color: #00AA00;">,</span> <span style="color: #6666ff;">.largeFont</span> <span style="color: #00AA00;">&#123;</span> 
.... <span style="color: #808080; font-style: italic;">/*common properties*/</span>
<span style="color: #00AA00;">&#125;</span>
&nbsp;
<span style="color: #6666ff;">.smallFont</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">background</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">url</span><span style="color: #00AA00;">&#40;</span>...<span style="color: #00AA00;">&#41;</span> <span style="color: #00AA00;">&#125;</span> 
...</pre></div></div>

<p>But I didn&#8217;t use that because it will be easier to declare as is now, if you want to use different sized images or different styles for each button. </p>
<p class="note">If you want to have multiple styles in the same page, just use the CSS scope</p>
<p>For eg:</p>

<div class="wp_syntax"><div class="code"><pre class="css css" style="font-family:monospace;"> <span style="color: #cc00cc;">#container1</span> <span style="color: #6666ff;">.smallFont</span> <span style="color: #00AA00;">&#123;</span> ... <span style="color: #00AA00;">&#125;</span>
<span style="color: #cc00cc;">#container2</span> <span style="color: #6666ff;">.smallFont</span> <span style="color: #00AA00;">&#123;</span> ... <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Now for the disabled state I used same style for all buttons. Using opacity filter is the easiest way to imitate a disabled button. Here for IE8, I have used an extra style after googling around.</p>
<h3>The jQuery function</h3>
<p>I didn&#8217;t write it as a jQuery plugin because I didn&#8217;t find it useful to have the chainable functionality.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> fontSize<span style="color: #009900;">&#40;</span>container<span style="color: #339933;">,</span> target<span style="color: #339933;">,</span> minSize<span style="color: #339933;">,</span> defSize<span style="color: #339933;">,</span> maxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #009966; font-style: italic;">/*Editable settings*/</span>
	<span style="color: #003366; font-weight: bold;">var</span> minCaption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Make font size smaller&quot;</span>; <span style="color: #006600; font-style: italic;">//title for smallFont button</span>
	<span style="color: #003366; font-weight: bold;">var</span> defCaption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Make font size default&quot;</span>; <span style="color: #006600; font-style: italic;">//title for defaultFont button</span>
	<span style="color: #003366; font-weight: bold;">var</span> maxCaption <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;Make font size larger&quot;</span>; <span style="color: #006600; font-style: italic;">//title for largefont button</span>
&nbsp;
&nbsp;
	<span style="color: #006600; font-style: italic;">//Now we'll add the font size changer interface in container</span>
	smallFontHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;a href='javascript:void(0);' class='smallFont' title='&quot;</span> <span style="color: #339933;">+</span> minCaption <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&quot;</span> <span style="color: #339933;">+</span> minCaption <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/a&gt; &quot;</span>;
	defFontHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;a href='javascript:void(0);' class='defaultFont' title='&quot;</span> <span style="color: #339933;">+</span> defCaption <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&quot;</span> <span style="color: #339933;">+</span> defCaption <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/a&gt; &quot;</span>;
	largeFontHtml <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;&lt;a href='javascript:void(0);' class='largeFont' title='&quot;</span> <span style="color: #339933;">+</span> maxCaption <span style="color: #339933;">+</span><span style="color: #3366CC;">&quot;'&gt;&quot;</span> <span style="color: #339933;">+</span> maxCaption <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;&lt;/a&gt; &quot;</span>;
	$<span style="color: #009900;">&#40;</span>container<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">html</span><span style="color: #009900;">&#40;</span>smallFontHtml <span style="color: #339933;">+</span> defFontHtml <span style="color: #339933;">+</span> largeFontHtml<span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #006600; font-style: italic;">//Read cookie &amp;amp; sets the fontsize</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">cookie</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #003366; font-weight: bold;">var</span> cookie <span style="color: #339933;">=</span> target.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[#. ]/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #003366; font-weight: bold;">var</span> value <span style="color: #339933;">=</span> $.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span>cookie<span style="color: #009900;">&#41;</span>;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>value <span style="color: #339933;">!=</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'font-size'</span><span style="color: #339933;">,</span> parseInt<span style="color: #009900;">&#40;</span>value<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #006600; font-style: italic;">//on clicking small font button, font size is decreased by 1px</span>
	$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .smallFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span> 
		curSize <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;font-size&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		newSize <span style="color: #339933;">=</span> curSize <span style="color: #339933;">-</span> <span style="color: #CC0000;">1</span>;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&gt;=</span> minSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'font-size'</span><span style="color: #339933;">,</span> newSize<span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&lt;=</span> minSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .smallFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sdisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&lt;</span> maxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .largeFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ldisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		updatefontCookie<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> newSize<span style="color: #009900;">&#41;</span>; <span style="color: #006600; font-style: italic;">//sets the cookie </span>
&nbsp;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #006600; font-style: italic;">//on clicking default font size button, font size is reset</span>
	$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .defaultFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'font-size'</span><span style="color: #339933;">,</span> defSize<span style="color: #009900;">&#41;</span>;
		$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .smallFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sdisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .largeFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ldisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		updatefontCookie<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> defSize<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #006600; font-style: italic;">//on clicking large font size button, font size is incremented by 1 to the maximum limit</span>
	$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .largeFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">click</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		curSize <span style="color: #339933;">=</span> parseInt<span style="color: #009900;">&#40;</span>$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;font-size&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>;
		newSize <span style="color: #339933;">=</span> curSize <span style="color: #339933;">+</span> <span style="color: #CC0000;">1</span>;
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&lt;=</span> maxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>target<span style="color: #009900;">&#41;</span>.<span style="color: #660066;">css</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">'font-size'</span><span style="color: #339933;">,</span> newSize<span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span> 
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&gt;</span> minSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .smallFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">removeClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;sdisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>newSize <span style="color: #339933;">&gt;=</span> maxSize<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			$<span style="color: #009900;">&#40;</span>container <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot; .largeFont&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">addClass</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;ldisabled&quot;</span><span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span>
		updatefontCookie<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> newSize<span style="color: #009900;">&#41;</span>;
	<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span>;
&nbsp;
	<span style="color: #003366; font-weight: bold;">function</span> updatefontCookie<span style="color: #009900;">&#40;</span>target<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Private function for setting cookie</span>
		<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>$.<span style="color: #660066;">cookie</span> <span style="color: #339933;">!=</span> undefined<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//If cookie plugin available, set a cookie</span>
			<span style="color: #003366; font-weight: bold;">var</span> cookie <span style="color: #339933;">=</span> target.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[#. ]/g</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>;
			$.<span style="color: #660066;">cookie</span><span style="color: #009900;">&#40;</span>cookie<span style="color: #339933;">,</span> size<span style="color: #009900;">&#41;</span>;
		<span style="color: #009900;">&#125;</span> 
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I think the code is self explanatory. If you&#8217;ve any doubt in code, please feel free to ask here <img src='http://cool-javascripts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Usage</h3>
<p>Include the css file, then after including jQuery include this script like the following (Don&#8217;t forget to change the path as required. Also, you need to copy the images in correct folder as specified in CSS file or edit the CSS file to make it correct.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;font-controller.css&quot; /&gt;
&lt;script src=&quot;jquery-1.2.6.pack.js&quot;&gt;&lt;/script&gt; 
&lt;script src=&quot;font-controller.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;jquery.cookie.js&quot;&gt;&lt;/script&gt;</pre></div></div>

<p>The function can be called inside a $document.ready() as usual. For eg:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript javascript" style="font-family:monospace;">fontSize<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;#container&quot;</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;#content&quot;</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">9</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">12</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">20</span><span style="color: #009900;">&#41;</span>;</pre></div></div>

<p>Then inside your html create the empty container for holding the elements. Give it an ID or class, if possible ID.</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">&lt;div id=&quot;container&quot;&gt;&lt;/div&gt; ... 
&lt;div id=&quot;content&quot;&gt;... Font size of this element can be controlled.... &lt;/div&gt;</pre></div></div>

<p class="note">Do not copy paste the code from this page. Instead download the full demo from below link</p>
<h3>Demo</h3>
<p class="download">
<a class="opensame" rel="shadowbox" href="http://demos.cool-javascripts.com/jquery-fontsize-controller.html">View Demo</a> | <a class="opennew" href="http://demos.cool-javascripts.com/jquery-fontsize-controller.zip" target="_blank">Download full demo</a>
</p>
<p>Please feel free to post your comments and suggestions for improvement <img src='http://cool-javascripts.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  </p>


<p>Related posts:<ol><li><a href='http://cool-javascripts.com/jquery/vertical-alignment-of-contents-inside-an-element-using-jquery.html' rel='bookmark' title='Permanent Link: Vertical alignment of contents inside an element using jQuery'>Vertical alignment of contents inside an element using jQuery</a> <small>One of the old problems! Vertical alignment of contents inside...</small></li><li><a href='http://cool-javascripts.com/jquery/add-icons-to-your-links-automatically-using-jquery-css.html' rel='bookmark' title='Permanent Link: Add icons to your links automatically using jQuery &#038; CSS'>Add icons to your links automatically using jQuery &#038; CSS</a> <small>You want to show a particular icon to a particular...</small></li><li><a href='http://cool-javascripts.com/effects/make-curved-corners-with-jquery-corner-plugin.html' rel='bookmark' title='Permanent Link: Make curved corners with jQuery Corner plugin'>Make curved corners with jQuery Corner plugin</a> <small>If you want a curved edge for your element, the...</small></li></ol></p>
<p>Related posts brought to you by <a href='http://mitcho.com/code/yarpp/'>Yet Another Related Posts Plugin</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://cool-javascripts.com/jquery/building-a-reusabe-font-size-controller-interface-using-jquery.html/feed</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
	</channel>
</rss>

