mattbell87 / FontSizeDetector

A javascript module that can detect font size changes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

FontSizeDetector

This script is a JavaScript module that detects when the font size has changed. You can create a function to notify you every time the font is changed.

This is a self contained module, no external libraries are required to run it though it will run nicely beside one if you like!

Download

Please see the release page.

Usage Example

Put this in your HTML somewhere (head will be fine, make sure it's loaded first):

<script src="fsdetect.min.js" type="text/javascript"></script>

Then code something like this in your own JavaScript file to detect font size changes:

FontSizeDetector.changed( function(e)
{
    //This code is run every time the font size has been changed
    
    //Uncomment the below to see font size changes:
    //console.log(e);
});

What would this be used for?

If you've got a JavaScript file that detects and resizes accorinding to the screen size, you may also want to look at this. When a user changes their font size, be it through an older browser, a mobile browser or a plugin you may find that your script is breaking. I came across this when developing a carousel, everything worked fine until font size was changed!

Isn't there something like this built in to the browser?

Nope, there's an onresize event for the Window however this does not get triggered when someone changes their font size. There may be plans to add this to future browsers.

What if I want to unbind an event?

Sure, if you want to unbind an event that you've stored as a variable (eg. myFunction) just call this:

FontSizeDetector.unbind( myFunction );

Or if you just want to unbind everything:

FontSizeDetector.unbind();

About

A javascript module that can detect font size changes

License:GNU General Public License v2.0


Languages

Language:JavaScript 100.0%