Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Formats > ePub

Notices

Reply
 
Thread Tools Search this Thread
Old 09-26-2016, 06:30 AM   #1
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
How to start javascript when a page is seen by user in iBooks

Hi,

I have an EPUB3 with several files with javascript scripts. One file has a javascript routine that show a little animation in page when the file (page) is opened.
It works fine in ADE, but not in iBooks. The problem is that iBooks seems to "prepaginate" ebook in background, so it starts the javascript routine *before* the page is showed to user. So, when the user turns the page there is no animation because it started and ended during the iBooks prepagination process.
Is there a way to start a javascript script *only* when the user turns the page and see the content in iBooks?

Thank you for suggestions.

Fabrizio
fbrzvnrnd is offline   Reply With Quote
Old 09-26-2016, 09:25 AM   #2
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
Since I don't how to do this in plain JavaScript, I usually embed jQuery and use the following function:

Code:
$(document).ready(function() {
    // your code    
};
(You can download an example epub3 book with an embedded jQuery file here.)

If adding ready() doesn't do the trick, post an example epub3 file.
Doitsu is offline   Reply With Quote
Advert
Old 09-26-2016, 09:44 AM   #3
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,093
Karma: 18727053
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
I'm certainly not a javascript expert either, but if ibooks is running said script before you flip to that page I would think it is because the "page" is run when the file (chapter) is opened. If you can't get Doitsu's method to work, perhaps putting that page of text and associated JS into its own file will do the trick?? It may look funny when the epub is reflowed - the previous page could cut off midway down the screen - but at least you know that JS won't run until that page is opened.

FWIW
Turtle91 is offline   Reply With Quote
Old 09-26-2016, 12:10 PM   #4
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
Quote:
Originally Posted by Doitsu View Post
Since I don't how to do this in plain JavaScript, I usually embed jQuery and use the following function:

If adding ready() doesn't do the trick, post an example epub3 file.
The ready is not working... If you open the ebook with ADE, you can see the text disappear when you turn the page in chapter 3. If you open the ebook using iBooks, the text begin to disappear when you are still in chapter 1. If you wait some seconds before turn the page, you do not see the text at all...
(I used your example EPUB with some fast changes)

f.
Attached Files
File Type: epub jQuery_fn_epub3.epub (64.2 KB, 202 views)
fbrzvnrnd is offline   Reply With Quote
Old 09-26-2016, 12:11 PM   #5
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
Quote:
Originally Posted by Turtle91 View Post
I'm certainly not a javascript expert either, but if ibooks is running said script before you flip to that page I would think it is because the "page" is run when the file (chapter) is opened. If you can't get Doitsu's method to work, perhaps putting that page of text and associated JS into its own file will do the trick?? It may look funny when the epub is reflowed - the previous page could cut off midway down the screen - but at least you know that JS won't run until that page is opened.

FWIW
The chapter is in its own file.
fbrzvnrnd is offline   Reply With Quote
Advert
Old 09-26-2016, 03:13 PM   #6
Doitsu
Grand Sorcerer
Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.Doitsu ought to be getting tired of karma fortunes by now.
 
Doitsu's Avatar
 
Posts: 5,583
Karma: 22735033
Join Date: Dec 2010
Device: Kindle PW2
@fbrzvnrnd: I only have very limited JavaScript skills, but, IMHO, the code looks OK. This appears to be an iBooks bug feature.

The animation actually works with iBooks, but only once. (If you have a very fast Mac or iPad your might not even see it.)

It looks like iBooks caches chapter html files and doesn't reload them when they're re-selected via the TOC.

A workaround would be to disable the animation for iBooks apps.

You can test for iBooks apps with the following JavaScript function:

Code:
navigator.epubReadingSystem.name
It should return iBooks.
Doitsu is offline   Reply With Quote
Old 09-26-2016, 04:29 PM   #7
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
Quote:
Originally Posted by Doitsu View Post
The animation actually works with iBooks, but only once. (If you have a very fast Mac or iPad your might not even see it.)
This is ok. My problem is this: I open the ebook with iBooks. Chapter I.
I wait 60 sec. (for example). I flip page to chapter 3. The animation is gone.
I can see the animation only if I flip fast to chapter 3, or if I close the ebook and reopen it in chapter 3.
fbrzvnrnd is offline   Reply With Quote
Old 09-27-2016, 03:22 AM   #8
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
I suspect (but am not certain) that the solution is to watch for scroll events, check document.documentElement.scrollTop against the position of the element you care about, and then trigger your animation if the element is on the screen at the end of the scroll event.

Worth a try, anyway.
dgatwood is offline   Reply With Quote
Old 09-27-2016, 08:28 AM   #9
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
Quote:
Originally Posted by dgatwood View Post
I suspect (but am not certain) that the solution is to watch for scroll events, check document.documentElement.scrollTop against the position of the element you care about, and then trigger your animation if the element is on the screen at the end of the scroll event.

Worth a try, anyway.
Thank you for suggestion, I'll try soon. I have only a question: why scroll events? Ebook hasn't scroll...

f.
fbrzvnrnd is offline   Reply With Quote
Old 09-27-2016, 09:06 AM   #10
jhowell
Grand Sorcerer
jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.jhowell ought to be getting tired of karma fortunes by now.
 
jhowell's Avatar
 
Posts: 6,496
Karma: 84420419
Join Date: Nov 2011
Location: Tampa Bay, Florida
Device: Kindles
I don't have a solution to your problem and this is a bit off topic, but...

Amazon has samples of something they call "Kindle in Motion" which (among other things) supports animation that starts automatically when the user reaches its page. They haven't actually announced this feature yet and there is no information on the tools or markup required to create this effect.

Just something to keep in mind in case you want to put your book on Amazon eventually.
jhowell is offline   Reply With Quote
Old 09-30-2016, 12:45 AM   #11
dgatwood
Curmudgeon
dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.dgatwood ought to be getting tired of karma fortunes by now.
 
dgatwood's Avatar
 
Posts: 629
Karma: 1623086
Join Date: Jan 2012
Device: iPad, iPhone, Nook Simple Touch
Quote:
Originally Posted by fbrzvnrnd View Post
Thank you for suggestion, I'll try soon. I have only a question: why scroll events? Ebook hasn't scroll...
It is still laying out the content in the same basic way as it would for a continuous flow with scrolling, just with a lot of extra logic at the page boundaries. And the reading position is still represented internally as a position within that content flow. In effect, it is scrolling, even though it isn't scrolling.
dgatwood is offline   Reply With Quote
Old 09-29-2017, 09:40 AM   #12
fbrzvnrnd
Fanatic
fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.fbrzvnrnd ought to be getting tired of karma fortunes by now.
 
Posts: 554
Karma: 400004
Join Date: Feb 2009
Device: ONYX M96
I do not think the scroll position could work: every chapter is a new xhtml file, so I got a different value (0) for each page.
I have the same problem when I use a script in a chapter that uses the localstorage.
For example: chapter 1, after a user action, put a "yes" value in locastorage.

Chapter 4, if the value in localstorage is "yes", must use red color for paragraph.

This is working in ADE. But iBooks starts ALL the scripts of ALL the pages when load the ePub the first time. So no way to check the "yes" value in localstorage.
fbrzvnrnd is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Loading page per page option for iBooks? momoha ePub 10 03-13-2015 01:25 AM
iBooks New User: Can I access them on my Windows PC? FatGuy Apple Devices 10 12-12-2014 09:34 AM
Print user manual/quick start guide? DennyP Calibre 6 03-14-2011 06:07 PM
JavaScript and interactivity in iBooks kjk Apple Devices 2 08-16-2010 10:14 AM
Can this be done - remove javascript from a page ScottMattes Workshop 1 05-17-2006 01:27 AM


All times are GMT -4. The time now is 01:08 PM.


MobileRead.com is a privately owned, operated and funded community.