0 votes
by (120 points)
Is it possible for the user to jump out of one passage into another, then get sent back to previous passage, but to the bit where they left off? My passages are quite long, so this functionality is important.

I have been trying to read the documentation, but I was looking for how to set up anchors in html. I tried that, couldn't get it to work, probably because I'm not a coder.

However I'm told it may be easier to capture the scroll position.

I don't know what that means. Also relevant, I'm brand new to this.

Downloaded Twine a few days ago so I guess I'm using the latest everything.

1 Answer

0 votes
by (63.1k points)
(function () {
    'use strict';

    var scrollPos = {};

    prehistory['capture-scroll'] = function () {
        if (tags().includes('no-scroll')) {
            return;
        }
        scrollPos[passage()] = $(document.documentElement).scrollTop();
    };
    postdisplay['restore-scroll'] = function () {
        $(document.documentElement).scrollTop(scrollPos[passage()]);
    };
}());

The above code will capture the scroll value when passage transition starts to restore later. It may not work with the <<back>> macro, but should work with <<return>>, previous(), and normal links just fine.

...