rough-stuff /rough-notation

Create and animate hand-drawn annotations on a web page

★ 9,746⑂ 241👁 47⑃ 35● 55▤ 0
TypeScriptMITCreated 2020-05-25roughnotation.com/
+2
Daily
9,746
stars
241
forks
47
watchers
35
prs
55
issues
0
releases

README

!Rough Notation logo

 Rough Notation

A small JavaScript library to create and animate annotations on a web page.

Rough Notation uses RoughJS to create a hand-drawn look and feel. Elements can be annotated in a number of different styles. Animation duration can be configured, or just turned off.

Rough Notation is 3.83kb in size when gzipped.

Visit website to see it in action and check out the source code for the website

 Installation

You can add rough-notation to your project via npm


npm install --save rough-notation


Or load the ES module directly

html



Or load the IIFE version which created a RoughNotation object in your scope.

html



 Usage

Create an annotation object by passing the element to annotate, and a config to describe the annotation style. 
Once you have the annotation object, you can call show() on it to show the annotation

javascript
import { annotate } from 'rough-notation';
// Or using unpkg
// import { annotate } from 'https://unpkg.com/rough-notation?module';

const e = document.querySelector('myElement');
const annotation = annotate(e, { type: 'underline' });
annotation.show();


Note: This will add an SVG element as a sibling to the element, which may be troublesome in certain situations like in a . You may want to create an inner  or  for the content to annotate.

 Annotation Group

rough-notation provides a way to order the animation of annotations by creating an annotation-group. Pass the list of annotations to create a group. When show is called on the group, the annotations are animated in order.

javascript
import { annotate, annotationGroup } from 'rough-notation';

const a1 = annotate(document.querySelector('e1'), { type: 'underline' });
const a2 = annotate(document.querySelector('e3'), { type: 'box' });
const a3 = annotate(document.querySelector('e3'), { type: 'circle' });

const ag = annotationGroup([a3, a1, a2]);
ag.show();


 Live examples
I have created some basic examples on Glitch for you to remix and play with the code:

Basic demo

Annotation group demo

 Configuring the Annotation

When you create an annotation object, you pass in a config. The config only has one mandatory field, which is the type of the annotation. But you can configure the annotation in many ways. 

 type
This is a mandatory field. It sets the annotation style. Following are the list of supported annotation types:

 __underline__: This style creates a sketchy underline below an element.
 __box__: This style draws a box around the element.
 __circle__: This style draws a circle around the element.
 __highlight__: This style creates a highlight effect as if marked by a highlighter.
 __strike-through__: This style draws horizontal lines through the element.
 __crossed-off__: This style draws an 'X' across the element.
 __bracket__: This style draws a bracket around an element, usually a paragraph of text. By default on the right side, but can be configured to any or all of left, right, top, bottom.

 animate
Boolean property 

Top issues

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON