What javascript works as expected in epub using iBooks?

1.2k views Asked by At

I am writing a footnote popup tooltip for epubs at the moment and I'm frustrated with the lack of documentation available on what javascript works and doesn't work inside epub, using iBooks specifically.

In my experience, using jQuery, doing a basic show/hide of an element does work, but DOM manipulation does not, and getting positions of elements is sketchy at best.

Has anyone worked with javascript in epub before and is willing to share best practices? Is it advisable to use jQuery, or can you get more functionality using vanilla javascript? Thanks!

2

There are 2 answers

0
AudioBubble On

The overwhelming majority of JS stuff is going to work fine in iBooks, including DOM manipulation. With regard to positions, however, the basic concept of positions is different in an ebook (although with iBooks 3.0's new scrolling mode, it becomes more like a traditional web page), and you probably want to limit position logic to determining if something is on or off the screen. If it's not on the screen, trying to scroll to it by setting scollPos or something similar is not going to work well if at all; instead, try jumping to the location in question with something like location.href="foo.xhtml#myanchor;.

0
widged On

I tried running an HTML widget with jqPlot (http://www.jqplot.com/), a graphing jquery library, and it worked just fine on the iPad. You could check their source code.