diff --git a/txt.js/txt.js b/txt.js/txt.js index bf07179..50f9d55 100644 --- a/txt.js/txt.js +++ b/txt.js/txt.js @@ -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, '
'); $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(); });