SIGN UP MEMBER LOGIN:    
ARTICLE

jQuery Change the Text Size (zoom in and out)

Posted by Shinuraj Articles | JQuery February 05, 2011
jQuery Change the Text Size (zoom in and out).
Reader Level:
Download Files:
 

Try it out the text resize functionality using jQuery.

Add this code in the head section:

<script type="text/javascript" src="./js/jquery-1.4.4.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('a').click(function() {
            var os = $('p').css('font-size');
            var num = parseFloat(os, 10);
            var px = os.slice(-2);

            $('p').css('font-size', num / 1.4 + px);
            if (this.id == 'larger') {
                $('p').css('font-size', num * 1.4 + px);
            }
        });
    });
</script>

HTML:

<body>

<a href="#" id ="larger">Larger [+]</a>
<br>
<
a href="#" id="smaller">Smaller [-]</a>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud

exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

</body>

Thanks
Shinu
 

Login to add your contents and source code to this article
share this article :
post comment
 

Hi Pete , the os.slice(-2) is used to get the unit of measurement, ie px, pt etc.. the last 2 places will provide this information that is why -2. You can just alert the os and check what is coming in the last 2 place. var os = $('p').css('font-size'); alert(os); hope this helps. -shinu

Posted by Shinuraj Feb 08, 2011

Mind explaining why the slice is -2? I know its right but why would it have to be -2? Thanks for a quick intro into jQuery!

Posted by Pete Hobbs Feb 07, 2011

Simple and nice article but try to add some images.

Posted by Sapna Feb 06, 2011

This must be in Blog section..

Posted by Suthish Nair Feb 05, 2011
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
Team Foundation Server Hosting
Become a Sponsor