Modal-Style Text Selection with Fokus

By  on  

Every once in a while I find a tiny JavaScript library that does something very specific, very well.  My latest find, Fokus, is a utility that listens for text selection within the page, and when such an event occurs, shows a beautiful modal dialog in the background of the entire page, allowing only the highlighted block to display at it's normal mode.

The HTML

Nothing special needs to be done with the page HTML, and you don't create "active" zones -- simply include the JavaScript file at the bottom of the page:

<!-- at bottom of the page -->
<script src="fokus/js/fokus.min.js" async></script>

The overlay elegantly fades in and out.  Canvas is used to create the overlay, and CSS' pointer-events property is used to ensure event handling consistency.  It would be great if Fokus was a bit more modular, including allowing active zones and customized overlay color, but it's hard to complain about anything else with Fokus.

Fokus isn't a necessity for any site, but I was taken aback by how smooth and accurate Fokus is.  Weighing in at just 3KB, it's an impressive little library.  Have an idea for how you'd use Fokus?  Share it!

Recent Features

  • By
    I&#8217;m an Impostor

    This is the hardest thing I've ever had to write, much less admit to myself.  I've written resignation letters from jobs I've loved, I've ended relationships, I've failed at a host of tasks, and let myself down in my life.  All of those feelings were very...

  • By
    Write Simple, Elegant and Maintainable Media Queries with Sass

    I spent a few months experimenting with different approaches for writing simple, elegant and maintainable media queries with Sass. Each solution had something that I really liked, but I couldn't find one that covered everything I needed to do, so I ventured into creating my...

Incredible Demos

  • By
    Generate Dojo GFX Drawings from SVG Files

    One of the most awesome parts of the Dojo / Dijit / DojoX family is the amazing GFX library.  GFX lives within the dojox.gfx namespace and provides the foundation of Dojo's charting, drawing, and sketch libraries.  GFX allows you to create vector graphics (SVG, VML...

  • By
    MooTools &#038; Printing &#8211; Creating a Links Table of Contents

    One detail we sometimes forget when considering print for websites is that the user cannot see the URLs of links when the page prints. While showing link URLs isn't always important, some websites could greatly benefit from doing so. This tutorial will show you...

Discussion

  1. patrick

    why not using it when using html5 contenteditable. it would play very nice together by let the user focus on the content he wants to edit.

  2. nice find. one thing; your website search box is broke. i couldn’t search for anything directly from the box and i had to use google for searching your website.

  3. smashercosmo

    Nice plugin. But I think, that implementation is too complex. It would be rather simpler to add outline: 999px solid rgba(0,0,0,0.7) to the focused block instead of rendering canvas.

  4. Nice… but until I was told what to do to make it work in the demo I would never have known! And that’s where it falls down.

  5. You could totally use this tool to launch a submenu that allows you to print it, send it to someone or post to twitter, etc. It would be super cool and as always you rock for puttin’ this out.

    • Alex

      This is really the best idea for this snippet. Thanks for sharing!

  6. how can you have an option to edit the text selected?
    Thank you

  7. s23q

    where is this to download??

Wrap your code in <pre class="{language}"></pre> tags, link to a GitHub gist, JSFiddle fiddle, or CodePen pen to embed!