twbs / bootstrap

The most popular HTML, CSS, and JavaScript framework for developing responsive, mobile first projects on the web.
https://getbootstrap.com
MIT License
170.93k stars 78.88k forks source link

ScrollSpy: improve active feedback #41016

Open guilhas07 opened 2 weeks ago

guilhas07 commented 2 weeks ago

Motivation & Context

Current ScrollSpy behavior had some shortcomings when it comes to detecting the correct active class.

Solution

To fix this I simplified the current logic, by adding an active state for all sections and keeping track of the previous highlighted section. The current rational is to highlight the first section that is intersecting at all times.

Different logic for scrolling up or down and custom thresholds are removed due to not being needed anymore.

Note: This is a first draft, so I didn't delve deeper into all of the code that can be simplified. I would be grateful for any feedback. Thank you for your time and for this amazing project!

Changes

Scroll Behaviour:

https://github.com/user-attachments/assets/6db60726-699f-43fa-847b-52e28d59acc2

https://github.com/user-attachments/assets/3c060388-9749-457d-971d-05b6e8b7cedd

Click Behaviour:

https://github.com/user-attachments/assets/ca1f2586-3c90-4e03-8955-c2ed4badcdf3

https://github.com/user-attachments/assets/78e22712-3a31-4188-b53d-08851885e5c4

Type of changes

Checklist

Live Previews

https://deploy-preview-41016--twbs-bootstrap.netlify.app/docs/5.3/getting-started/introduction/

Manchmal1 commented 2 weeks ago

Was muß ich machen um die auf dem Fernseher zu sehen bitte