Skip to the content

X-ray lens

A rectangular window follows the pointer and, inside it, the page shows what is under it.

Become a member to unlock the full effect today.

Join now

Already a member? Sign in

Documentation

  1. Copy to Webflow

    Add Geist and Geist Mono to your site's fonts (Site settings, Fonts, Google Fonts) before pasting: Webflow removes any font your site has not installed.

  2. Add custom CSS

  3. Add custom JS

  4. Tune it

    Custom attributes
    Select the section on the canvas and open the Settings panel. Under Custom attributes, add a pair: the name on the left, the value on the right.
    Custom attributeWhat it does
    data-xray-lens Marks the section the effect plays on. It takes no value: leave the value field empty.
    data-xray-lens-top Marks the layer on top, the page as it reads normally. The engine uses it to find the layer underneath, the block that follows it. [ Optional ]
    data-xray-lens-under Marks the layer the window reveals. Without it the engine takes the block right after the one marked data-xray-lens-top, and with neither mark it warns in the console and does not mount. [ Optional ]
    Settings
    Every setting is a custom attribute too, added the same way and on the same section. An attribute always wins over the defaults written in the code.
    AttributeDefaultWhat it is
    data-width clamp(260px, 34vw, 470px) Width of the window the lens opens, any CSS unit.
    data-height clamp(150px, 20vw, 280px) Height of that window, any CSS unit.
    data-corner 0 Corner radius of the window and of the frame, any CSS unit.
    data-lag 0.16 How far the window trails behind the pointer, in seconds.
    data-readout empty One line under the frame, naming what the window opens on. Options: any short label, or empty for no line at all.
    data-touch follow What a finger does on a touch screen. Options: follow, the window opens under the finger and closes when it lifts; off, a touch screen gets the page alone.

What it does

X-ray lens is a cursor animation for Webflow and vanilla JavaScript, with no library. Also called x-ray cursor effect, cursor reveal effect or cursor mask reveal.

A rectangular window follows the pointer and, inside it, the page shows what is under it. Two layers sit on the same boxes, both of them ordinary HTML, and the top one is cut open wherever the lens goes. In the reference demo a product page hides the mill's own record for the paper it is selling: lot number, basis weight, moisture at wrap, a cross section of the sheet. The point is that the layer underneath is real content, not decoration, so the effect says something instead of just moving. A thin accent frame with corner brackets, a crosshair and a small readout mark the opening. The window is a CSS clip-path driven by two custom properties, so following the pointer costs nothing but writing two values, and the lens trails slightly behind with time-based smoothing.

Updated

Questions

The two layers are two sibling blocks in the Designer: build the first as any section, duplicate it, then rewrite the words. Put data-xray-lens on the block that holds both, data-xray-lens-top on the page as it reads normally and data-xray-lens-under on the layer the window reveals.

No library. The window is a CSS clip-path driven by two custom properties, and the script writes those two values to follow the pointer. Both layers are ordinary HTML, with no image trick.

Set data-width and data-height on the block. They default to clamp(260px, 34vw, 470px) and clamp(150px, 20vw, 280px), and accept any CSS unit, clamp() and calc() included. Smaller, the window is a peephole that cuts every line of text it crosses, and larger, the layer underneath takes over the page.

Fix it in the copy, by matching lengths. Give both layers the same typography and write each block underneath to roughly the character count of the block it hides, so the lines break in the same places. Padding belongs on the two layers, not on the block that carries data-xray-lens, where it is only safe in browsers that support CSS anchor positioning.

Yes. By default the window opens under the finger, follows it while it slides and closes when it lifts. Set data-touch="off" to give touch screens the page alone, which is worth considering on a phone since the second layer is a real weight for an effect nobody can hover.