Skip to content
This repository was archived by the owner on Aug 16, 2019. It is now read-only.

Commit 2bc9c88

Browse files
committed
use vertical middle as current reading position
1 parent e5dc795 commit 2bc9c88

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

reading_progress.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
supportsPassive = true
88
}
99
})
10-
window.addEventListener("test", null, opts)
10+
window.addEventListener('test', $.noop, opts)
11+
window.removeEventListener('test', $.noop)
1112
} catch (e) { }
1213

1314
$(document).ready(function () {
15+
var $bar = $('.reading-progress-bar')
1416
window.addEventListener('scroll', function () {
17+
var $win = $(window)
1518
var $post = $('.post-block')
16-
var h = $(window).scrollTop() - $post.position().top
19+
var winmid = $win.scrollTop() + $win.height() / 2 //assume reader will focus on middle of screen(vertical)
20+
var h = winmid - $post.position().top
1721
var percent = Math.round(h / $post.height() * 100)
1822
if (percent < 0) percent = 0
1923
if (percent > 100) percent = 100
20-
$('.reading-progress-bar').css('width', percent + '%')
24+
$bar.css('width', percent + '%')
2125
}, supportsPassive ? { passive: true } : false)
2226
})
2327
})()

0 commit comments

Comments
 (0)