Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow "scroll spy" with the current section highlighted #1309

Closed
3 tasks done
samuelcolvin opened this issue Oct 17, 2019 · 3 comments
Closed
3 tasks done

allow "scroll spy" with the current section highlighted #1309

samuelcolvin opened this issue Oct 17, 2019 · 3 comments

Comments

@samuelcolvin
Copy link
Contributor

I checked that...

  • ... the documentation does not mention anything about my idea
  • ... to my best knowledge, my idea wouldn't break something for other users
  • ... there are no open or closed issues that are related to my idea

Description

It would be great if an extra attribute was set on md-nav__link to allow custom CSS to change how the page TOC looks to highlight the current item, rather than blur items above the current page y-offset.

This could be implemented by something like adding data-md-state="current" to the TOC item corresponding to the top section visible on the screen.

Use Cases

I'd like to highlight the page-TOC item corresponding to the section currently on screen, similar to:

I'm not suggesting editing the standard CSS and thereby enforcing a change for most users, just allow users to implement this themselves by adding css like:

.md-nav__link[data-md-state=blur] {
    color: rgba(0,0,0,.87);  /* remove blurring */
}
.md-nav__link[data-md-state=current] {
    font-weight: 700;
}
@samuelcolvin
Copy link
Contributor Author

Should involve a relatively small change to

/* Scroll direction is down */
if (this.offset_ <= offset) {
for (let i = this.index_ + 1; i < this.els_.length; i++) {
if (this.anchors_[i].offsetTop - (56 + 24) <= offset) {
if (i > 0)
this.els_[i - 1].dataset.mdState = "blur"
this.index_ = i
} else {
break
}
}
/* Scroll direction is up */
} else {
for (let i = this.index_; i >= 0; i--) {
if (this.anchors_[i].offsetTop - (56 + 24) > offset) {
if (i > 0)
this.els_[i - 1].dataset.mdState = ""
} else {
this.index_ = i
break
}
}
}

Should be entirely backwards compatible.

@squidfunk
Copy link
Owner

Exact duplicate of #1102 ;-) Will be fixed with #1306, but this will take some time.

@samuelcolvin
Copy link
Contributor Author

ha, looked but couldn't find a similar issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants