Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Fix audio 'scroll to element' for horizontal #86

Merged

Conversation

kjantzer
Copy link
Member

@kjantzer kjantzer commented Jul 9, 2016

Tested on both books.

@hebertialmeida
Copy link
Member

Hey I tested and worked perfectly for horizontal, but for vertical scroll it is not working for me, I have tried but seems that there is something wrong. May we have to check the direction and do only one direction scroll. What do you think?

@hebertialmeida
Copy link
Member

I have being playing with some code, I found a solution based on your code. I don't know if it is the best way to handle this:

function goToEl(el) {
    var top = document.body.scrollTop;
    var elTop = el.offsetTop - 20;
    var bottom = window.innerHeight + document.body.scrollTop;
    var elBottom = el.offsetHeight + el.offsetTop + 60

    var clientWidth = document.documentElement["clientWidth"];
    var scrollWidth = document.body["scrollWidth"];

    if (scrollWidth > clientWidth) {
        var elLeft = document.body.clientWidth * Math.floor(el.offsetTop / window.innerHeight);
        document.body.scrollLeft = elLeft;
    } else if(elBottom > bottom || elTop < top) {
        document.body.scrollTop = el.offsetTop - 20
    }

    return el;
}

It is working for both orientations.

@kjantzer
Copy link
Member Author

I was just finishing up testing my fix too.

I just added this before setting scroll left:

if( document.body.scrollTop == 0 ){

@hebertialmeida
Copy link
Member

Perfect! Much better solution as always 👍

@hebertialmeida hebertialmeida merged commit 8cb435f into FolioReader:horizontal-scroll Jul 11, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
2 participants