Domanda

I want to be able to ask the pdf viewer a multiple choice question when he visits page X.

Can someone please give me a high level of how that can be achieved using pdf.js library (or other library)?

I am thinking there should be a way where my front-end detects that user now scrolled to page X and thus executes the javascript function to ask the question. Am I on the right track?

I will further build on your reply. I have done my homework before posting here.

È stato utile?

Soluzione

Use .scrollTop() (jQuery) to see how far a user has scrolled through a page:

$(document).scroll(function(){
    if ($('.pageX').scrollTop() > 0) {
       /*JavaScript to be executed*/
    }
});

I have given page X a class of pageX, and the instance that page X fills up the entire window your JavaScript will start.

.scrollTop() looks for how many pixels of the element are above the page (out of site), so if you wanted your functions to begin before the window is filled with page X you can change the 0 to a negative number, eg. if ($('.pageX').scrollTop() > -70) will start your javascript when page X is filling up most of the window.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top