Add fallback if InteractionObserver is unavailable

pull/1661/head
Uku Taht 5 years ago
parent 9d792f5b8c
commit 97ce263c84

@ -2,6 +2,14 @@ import React from 'react';
export default class extends React.Component {
componentDidMount() {
if ('IntersectionObserver' in window) {
this.attachObserver()
} else {
this.props.onVisible && this.props.onVisible()
}
}
attachObserver() {
this.observer = new IntersectionObserver((entries) => {
if (entries[0].isIntersecting) {
this.props.onVisible && this.props.onVisible()

@ -25,12 +25,10 @@ function Historical(props) {
return null
}
const navClass = props.site.embedded ? 'relative' : 'sticky'
return (
<div className="mb-12">
<div id="stats-container-top"></div>
<div className={`${navClass} top-0 sm:py-3 py-2 z-10 ${props.stuck && !props.site.embedded ? 'fullwidth-shadow bg-gray-50 dark:bg-gray-850' : ''}`}>
<div className={`relative top-0 sm:py-3 py-2 z-10 ${props.stuck && !props.site.embedded ? 'sticky fullwidth-shadow bg-gray-50 dark:bg-gray-850' : ''}`}>
<div className="items-center w-full flex">
<div className="flex items-center w-full">
<SiteSwitcher site={props.site} loggedIn={props.loggedIn} currentUserRole={props.currentUserRole} />

@ -10,6 +10,12 @@ export const withPinnedHeader = (WrappedComponent, selector) => {
}
componentDidMount() {
if ('IntersectionObserver' in window) {
this.attachObserver()
}
}
attachObserver() {
this.observer = new IntersectionObserver((entries) => {
if (entries[0].intersectionRatio === 0)
this.setState({ stuck: true });

Loading…
Cancel
Save