txt.js: improved scrolling

This commit is contained in:
rlx 2016-01-10 12:56:06 +05:30
parent 1259c8974b
commit f5dfeb2ce0

View file

@ -36,24 +36,22 @@ txtjs.open = function(url) {
.on({
mousedown: function(e) {
var offset = 'offsetY' in e ? e.offsetY : e.layerY;
document.body.scrollTop = offset / factor;
//Ox.print('!', offset)
document.body.scrollTop = offset / factor + margin - 16;
}
})
.appendTo($scroll),
textHeight, scrollTextHeight, factor;
factor, margin;
text = Ox.encodeHTMLEntities(text)
.replace(/\r\n/g, '\n')
.replace(/[\r\n]/g, '<br>');
$text.html(text);
$scrollText.html(text);
window.onresize = function() {
textHeight = $text[0].clientHeight - window.innerHeight,
scrollTextHeight = $scrollText[0].clientHeight - (window.innerHeight - 32),
factor = scrollTextHeight / textHeight;
margin = $text.width() * 0.1;
factor = $scrollText[0].clientHeight / $text[0].clientHeight;
};
window.onscroll = function() {
$scroll[0].scrollTop = window.pageYOffset * factor;
$scroll[0].scrollTop = (window.pageYOffset - margin + 16) * factor;
};
window.onresize();
});