mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Fix initialization logic of toc blurring
This commit is contained in:
parent
96ae06f25c
commit
113ba5fd8b
File diff suppressed because one or more lines are too long
@ -109,7 +109,7 @@
|
||||
<script src="https://cdn.mathjax.org/{{ path }}"></script>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
<script src="{{ base_url }}/assets/javascripts/application-e4e6991dc0.js"></script>
|
||||
<script src="{{ base_url }}/assets/javascripts/application-cd89c74ae5.js"></script>
|
||||
<script>
|
||||
/* Configuration for application */
|
||||
var config = {
|
||||
|
@ -41,10 +41,9 @@ export default class Blur {
|
||||
this.index_ = 0
|
||||
this.offset_ = window.pageYOffset
|
||||
|
||||
/* Index anchor node offsets for fast lookup, and deduct the static offset
|
||||
of the header (56px) and sidebar offset (24px), see _permalinks.scss */
|
||||
/* Index anchor node offsets for fast lookup */
|
||||
this.anchors_ = [].map.call(this.els_, el => {
|
||||
return document.querySelector(el.hash).offsetTop - (56 + 24)
|
||||
return document.querySelector(el.hash)
|
||||
})
|
||||
}
|
||||
|
||||
@ -57,6 +56,9 @@ export default class Blur {
|
||||
|
||||
/**
|
||||
* Update anchor states
|
||||
*
|
||||
* Deduct the static offset of the header (56px) and sidebar offset (24px),
|
||||
* see _permalinks.scss for more information.
|
||||
*/
|
||||
update() {
|
||||
const offset = window.pageYOffset
|
||||
@ -68,7 +70,7 @@ export default class Blur {
|
||||
/* Scroll direction is down */
|
||||
if (this.offset_ <= offset) {
|
||||
for (let i = this.index_ + 1; i < this.els_.length; i++) {
|
||||
if (this.anchors_[i] <= offset) {
|
||||
if (this.anchors_[i].offsetTop - (56 + 24) <= offset) {
|
||||
if (i > 0)
|
||||
this.els_[i - 1].dataset.mdState = "blur"
|
||||
this.index_ = i
|
||||
@ -80,7 +82,7 @@ export default class Blur {
|
||||
/* Scroll direction is up */
|
||||
} else {
|
||||
for (let i = this.index_; i >= 0; i--) {
|
||||
if (this.anchors_[i] > offset) {
|
||||
if (this.anchors_[i].offsetTop - (56 + 24) > offset) {
|
||||
if (i > 0)
|
||||
this.els_[i - 1].dataset.mdState = ""
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user