🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

fontonload

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fontonload

Cross browser detecting font loads, without checking by timer (setTimeout / setInterval).

latest
Source
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

fontonload

Build Status

Cross browser detecting web font loading, without checking by timer (setTimeout / setInterval).

中文

Usage

  • Patch your font with the patch.ttf file, which include a blank graph (non-spacing and no-marking) on U+FFFD
  • Declare the @font-face in your CSS.
  • Load the library.
FontOnload('fontname', {
  eotFile: './fonts/fontname.eot',
  success: function() {
  },
  fail: function(e) {
    console.log(e.name)
  }
})

You can check the demo page to see if it works.

How it Works

  • It uses the CSS Font Loading Module when available.
  • For browsers which can auto trigger scroll event. It uses a scroller element, which contains an U+FFFD charactor, to detect the font loading. When your patched font load, the height and width of the detection element will become 0, that will trigger a scroll event. It's similar to smhn's article, but simple (no embedded font) in detection.
  • For IE 6 – 9, these browsers won't trigger a scroll event after height/width decreased. But fortunately I found that they don't have FOUT if the font file is in cache, so the code just preload the eot font to make sure the font file is in cache. The preload works is make by iframe, and detect the loading by it's onload event. (@font-face will block onload event)
  • It exclude the browser which don't support web font (BlackBerry 5/6, Opera Mini, Windows Phone 7/7.5)

License

MIT License

Keywords

font

FAQs

Package last updated on 17 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts