feat: migrate Sticky component

This commit is contained in:
chenjiahan 2020-07-26 15:16:18 +08:00
parent 01c7409e6e
commit 4ad0c396ef

View File

@ -1,6 +1,6 @@
import { isHidden } from '../utils/dom/style';
import { unitToPx } from '../utils/format/unit';
import { createNamespace, isDef, isServer } from '../utils';
import { createNamespace, isDef, inBrowser } from '../utils';
import { getScrollTop, getElementTop, getScroller } from '../utils/dom/scroll';
import { BindEventMixin } from '../mixins/bind-event';
@ -32,6 +32,8 @@ export default createComponent({
},
},
emits: ['scroll'],
data() {
return {
fixed: false,
@ -70,7 +72,7 @@ export default createComponent({
created() {
// compatibility: https://caniuse.com/#feat=intersectionobserver
if (!isServer && window.IntersectionObserver) {
if (inBrowser && window.IntersectionObserver) {
this.observer = new IntersectionObserver(
(entries) => {
// trigger scroll when visibility changed
@ -141,7 +143,7 @@ export default createComponent({
return (
<div style={style}>
<div class={bem({ fixed })} style={this.style}>
{this.slots()}
{this.$slots.default?.()}
</div>
</div>
);