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

Commit

Permalink
use vertical middle as current reading position
Browse files Browse the repository at this point in the history
  • Loading branch information
maple3142 committed Jan 19, 2018
1 parent e5dc795 commit 2bc9c88
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions reading_progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@
supportsPassive = true
}
})
window.addEventListener("test", null, opts)
window.addEventListener('test', $.noop, opts)
window.removeEventListener('test', $.noop)
} catch (e) { }

$(document).ready(function () {
var $bar = $('.reading-progress-bar')
window.addEventListener('scroll', function () {
var $win = $(window)
var $post = $('.post-block')
var h = $(window).scrollTop() - $post.position().top
var winmid = $win.scrollTop() + $win.height() / 2 //assume reader will focus on middle of screen(vertical)
var h = winmid - $post.position().top
var percent = Math.round(h / $post.height() * 100)
if (percent < 0) percent = 0
if (percent > 100) percent = 100
$('.reading-progress-bar').css('width', percent + '%')
$bar.css('width', percent + '%')
}, supportsPassive ? { passive: true } : false)
})
})()

0 comments on commit 2bc9c88

Please sign in to comment.