|
12 | 12 | height: 100vh; |
13 | 13 | margin: 0; |
14 | 14 | } |
15 | | - #annotated-text { |
| 15 | + .annotated-text { |
16 | 16 | font-size: 2em; |
17 | | - padding: 20px; |
| 17 | + padding: 4px; |
18 | 18 | border: 1px solid #ccc; |
19 | 19 | cursor: pointer; |
| 20 | + margin: 8px; |
20 | 21 | } |
21 | 22 | .instructions { |
22 | 23 | margin-top: 20px; |
|
26 | 27 | </style> |
27 | 28 | </head> |
28 | 29 | <body> |
29 | | - <div id="annotated-text">Click me to toggle the annotation.</div> |
| 30 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 31 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 32 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 33 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 34 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 35 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 36 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 37 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 38 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 39 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 40 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 41 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 42 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 43 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 44 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 45 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 46 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 47 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 48 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 49 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
| 50 | + <div class="annotated-text">Click me to toggle the annotation.</div> |
30 | 51 |
|
31 | 52 | <div class="instructions"> |
32 | 53 | This demo shows the animated `hide()` method. |
|
36 | 57 | <script> |
37 | 58 | const { annotate } = RoughNotation; |
38 | 59 |
|
39 | | - const el = document.getElementById("annotated-text"); |
40 | | - const annotation = annotate(el, { |
41 | | - type: "underline", |
42 | | - color: "red", |
43 | | - animationDuration: 1000, |
44 | | - animateOnHide: true, |
45 | | - }); |
| 60 | + const els = document.getElementsByClassName("annotated-text"); |
| 61 | + const annotations = Array.from(els).map((el) => |
| 62 | + annotate(el, { |
| 63 | + type: "underline", |
| 64 | + color: "red", |
| 65 | + animationDuration: 1000, |
| 66 | + animateOnHide: true, |
| 67 | + }) |
| 68 | + ); |
46 | 69 |
|
47 | | - el.addEventListener("click", () => { |
48 | | - if (annotation.isShowing()) { |
49 | | - annotation.hide(); |
50 | | - } else { |
51 | | - annotation.show(); |
52 | | - } |
53 | | - }); |
| 70 | + for (let i = 0; i < annotations.length; i++) { |
| 71 | + const annotation = annotations[i]; |
| 72 | + const el = els[i]; |
| 73 | + el.addEventListener("click", () => { |
| 74 | + if (annotation.isShowing()) { |
| 75 | + annotation.hide(); |
| 76 | + } else { |
| 77 | + annotation.show(); |
| 78 | + } |
| 79 | + }); |
| 80 | + } |
54 | 81 |
|
55 | 82 | // Initially show the annotation |
56 | 83 | annotation.show(); |
|
0 commit comments