futurepress / epub.js

Enhanced eBooks in the browser.
http://futurepress.org
Other
6.39k stars 1.09k forks source link

Update annotation #1177

Open atykhan-amplify opened 3 years ago

atykhan-amplify commented 3 years ago

While working with epub.js I've faced the necessity to update the annotation color. I haven't find the possibility of doing it within the Annotations class or other epub.js components. So I have to build my own workaround. Is there any possibility of doing it with the epub.js library?

sbatson5 commented 3 years ago

The annotations (which can be underlines or highlights) are just elements within an SVG that lives on your webpage. You can style them with CSS.

Styling highlights (make them gray):

.epubjs-hl,
.epubjs-hl g {
  fill: #aaa;
}

Styling underlines (make them gray, change line width):

.epubjs-ul line {
  stroke: #aaa;
  stroke-width: 2;
}
johnfactotum commented 3 years ago

The simplest way to update an annotation is probably just removing it and adding a new annotation. Both the old and new annotation have the same CFI, so the result is effectively an update.

youzi001 commented 1 year ago

@sbatson5 Where to use this code