1
0
mirror of https://github.com/squidfunk/mkdocs-material.git synced 2025-02-17 18:49:21 +01:00

Fixed incorrectly computed header height when using instant loading

This commit is contained in:
squidfunk 2022-04-07 22:20:32 +02:00
parent d926bb4c27
commit cc0f7a914a
4 changed files with 14 additions and 21 deletions

View File

@ -214,7 +214,7 @@
</script> </script>
{% endblock %} {% endblock %}
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/bundle.52fb055a.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.6e54b5cd.min.js' | url }}"></script>
{% for path in config["extra_javascript"] %} {% for path in config["extra_javascript"] %}
<script src="{{ path | url }}"></script> <script src="{{ path | url }}"></script>
{% endfor %} {% endfor %}

View File

@ -58,7 +58,6 @@ import { Main } from "../../main"
*/ */
export interface Header { export interface Header {
height: number /* Header visible height */ height: number /* Header visible height */
sticky: boolean /* Header stickyness */
hidden: boolean /* Header is hidden */ hidden: boolean /* Header is hidden */
} }
@ -143,22 +142,16 @@ function isHidden({ viewport$ }: WatchOptions): Observable<boolean> {
export function watchHeader( export function watchHeader(
el: HTMLElement, options: WatchOptions el: HTMLElement, options: WatchOptions
): Observable<Header> { ): Observable<Header> {
return defer(() => { return defer(() => combineLatest([
const styles = getComputedStyle(el) watchElementSize(el),
return of( isHidden(options)
styles.position === "sticky" || ]))
styles.position === "-webkit-sticky"
)
})
.pipe( .pipe(
combineLatestWith(watchElementSize(el), isHidden(options)), map(([{ height }, hidden]) => ({
map(([sticky, { height }, hidden]) => ({ height,
height: sticky ? height : 0,
sticky,
hidden hidden
})), })),
distinctUntilChanged((a, b) => ( distinctUntilChanged((a, b) => (
a.sticky === b.sticky &&
a.height === b.height && a.height === b.height &&
a.hidden === b.hidden a.hidden === b.hidden
)), )),