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>
{% endblock %}
{% 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"] %}
<script src="{{ path | url }}"></script>
{% endfor %}

View File

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