mirror of
https://github.com/the1812/Bilibili-Evolved.git
synced 2025-11-04 21:22:45 +08:00
Refactor scroll mask
This commit is contained in:
parent
aa3012f5bb
commit
37696aed23
@ -3,7 +3,6 @@
|
|||||||
class="fresh-home-video-list scroll-top scroll-bottom"
|
class="fresh-home-video-list scroll-top scroll-bottom"
|
||||||
:class="{ 'not-empty': videos.length > 0 }"
|
:class="{ 'not-empty': videos.length > 0 }"
|
||||||
>
|
>
|
||||||
<div class="fresh-home-video-list-mask left"></div>
|
|
||||||
<div ref="content" class="fresh-home-video-list-content">
|
<div ref="content" class="fresh-home-video-list-content">
|
||||||
<div v-if="videos.length === 0" class="fresh-home-video-list-empty">
|
<div v-if="videos.length === 0" class="fresh-home-video-list-empty">
|
||||||
<VLoading v-if="loading" />
|
<VLoading v-if="loading" />
|
||||||
@ -12,17 +11,17 @@
|
|||||||
<VideoCardWrapper
|
<VideoCardWrapper
|
||||||
v-for="video of videos"
|
v-for="video of videos"
|
||||||
v-else
|
v-else
|
||||||
|
ref="cards"
|
||||||
:key="video.id"
|
:key="video.id"
|
||||||
:data="video"
|
:data="video"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div class="fresh-home-video-list-mask right"></div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { intersectionObserve } from '@/core/observer'
|
|
||||||
import { VEmpty, VLoading } from '@/ui'
|
import { VEmpty, VLoading } from '@/ui'
|
||||||
import VideoCardWrapper from './VideoCardWrapper.vue'
|
import VideoCardWrapper from './VideoCardWrapper.vue'
|
||||||
|
import { setupScrollMask, cleanUpScrollMask } from './scroll-mask'
|
||||||
|
|
||||||
export default Vue.extend({
|
export default Vue.extend({
|
||||||
components: {
|
components: {
|
||||||
@ -40,57 +39,26 @@ export default Vue.extend({
|
|||||||
default: true,
|
default: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
observers: [],
|
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
watch: {
|
||||||
videos() {
|
videos() {
|
||||||
this.setupIntersection()
|
this.setupIntersection()
|
||||||
},
|
},
|
||||||
loading(loading: boolean) {
|
loaded() {
|
||||||
if (!loading) {
|
if (this.loaded) {
|
||||||
this.setupIntersection()
|
this.setupIntersection()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
beforeDestroy() {
|
||||||
|
cleanUpScrollMask(this.$el)
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async setupIntersection() {
|
async setupIntersection() {
|
||||||
await this.$nextTick()
|
await this.$nextTick()
|
||||||
const observers = this.observers as IntersectionObserver[]
|
setupScrollMask({
|
||||||
if (observers) {
|
container: this.$el,
|
||||||
observers.forEach(o => o.disconnect())
|
items: this.$refs.cards.map((c: Vue) => c.$el),
|
||||||
this.observers = []
|
})
|
||||||
}
|
|
||||||
const container = this.$refs.content as HTMLElement
|
|
||||||
const videoWrappers = dqa(container, '.fresh-home-video-card-wrapper') as HTMLElement[]
|
|
||||||
if (videoWrappers.length === 0) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const observerConfig: IntersectionObserverInit = { threshold: [1], root: container }
|
|
||||||
const [firstWrapper] = videoWrappers
|
|
||||||
const [firstObserver] = intersectionObserve(
|
|
||||||
[firstWrapper],
|
|
||||||
observerConfig,
|
|
||||||
records => records.forEach(r => {
|
|
||||||
const isScrollTop = r.isIntersecting && r.intersectionRatio === 1
|
|
||||||
this.$el.classList.toggle('scroll-top', isScrollTop)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
this.observers.push(firstObserver)
|
|
||||||
if (videoWrappers.length > 1) {
|
|
||||||
const lastWrapper = videoWrappers[videoWrappers.length - 1]
|
|
||||||
const [lastObserver] = intersectionObserve(
|
|
||||||
[lastWrapper],
|
|
||||||
observerConfig,
|
|
||||||
records => records.forEach(r => {
|
|
||||||
const isScrollBottom = r.isIntersecting && r.intersectionRatio === 1
|
|
||||||
this.$el.classList.toggle('scroll-bottom', isScrollBottom)
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
this.observers.push(lastObserver)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
offsetPage(offset: number) {
|
offsetPage(offset: number) {
|
||||||
const container = this.$refs.content as HTMLElement
|
const container = this.$refs.content as HTMLElement
|
||||||
@ -105,6 +73,7 @@ export default Vue.extend({
|
|||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import "common";
|
@import "common";
|
||||||
|
@import "./effects";
|
||||||
|
|
||||||
.fresh-home-video-list {
|
.fresh-home-video-list {
|
||||||
--card-height: var(--home-content-height);
|
--card-height: var(--home-content-height);
|
||||||
@ -114,6 +83,7 @@ export default Vue.extend({
|
|||||||
display: flex;
|
display: flex;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
width: 0;
|
width: 0;
|
||||||
|
@include scroll-mask-x(36px);
|
||||||
|
|
||||||
&-content {
|
&-content {
|
||||||
@include h-center();
|
@include h-center();
|
||||||
@ -133,35 +103,5 @@ export default Vue.extend({
|
|||||||
&.not-empty &-content {
|
&.not-empty &-content {
|
||||||
scroll-snap-type: x mandatory;
|
scroll-snap-type: x mandatory;
|
||||||
}
|
}
|
||||||
&-mask {
|
|
||||||
opacity: 0;
|
|
||||||
}
|
|
||||||
&.not-empty &-mask {
|
|
||||||
position: absolute;
|
|
||||||
pointer-events: none;
|
|
||||||
transition: .1s ease-out;
|
|
||||||
width: 36px;
|
|
||||||
opacity: 1;
|
|
||||||
height: 100%;
|
|
||||||
flex-shrink: 0;
|
|
||||||
top: 0;
|
|
||||||
z-index: 1;
|
|
||||||
&.left {
|
|
||||||
background: linear-gradient(to right, var(--home-base-color) 40%, rgba(0, 0, 0, 0) 100%);
|
|
||||||
left: -2px;
|
|
||||||
}
|
|
||||||
&.right {
|
|
||||||
background: linear-gradient(to left, var(--home-base-color) 40%, rgba(0, 0, 0, 0) 100%);
|
|
||||||
right: -2px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&.scroll-top .fresh-home-video-list-mask.left {
|
|
||||||
// background: linear-gradient(to right, var(--home-base-color) 0%, rgba(0, 0, 0, 0) 100%);
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
&.scroll-bottom .fresh-home-video-list-mask.right {
|
|
||||||
// background: linear-gradient(to left, var(--home-base-color) 0%, rgba(0, 0, 0, 0) 100%);
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
}
|
}
|
||||||
animation: bounce-y-#{$offset-in-px} 0.4s ease-out;
|
animation: bounce-y-#{$offset-in-px} 0.4s ease-out;
|
||||||
}
|
}
|
||||||
@mixin scroll-mask-x {
|
@mixin scroll-mask-x($mask-width: 24px) {
|
||||||
&::before,
|
&::before,
|
||||||
&::after {
|
&::after {
|
||||||
content: "";
|
content: "";
|
||||||
@ -34,7 +34,7 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
transition: .1s ease-out;
|
transition: .1s ease-out;
|
||||||
width: 24px;
|
width: $mask-width;
|
||||||
opacity: 1;
|
opacity: 1;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
@ -122,7 +122,7 @@ export default Vue.extend({
|
|||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import "common";
|
@import "common";
|
||||||
@import "./effects";
|
@import "../../../effects";
|
||||||
|
|
||||||
.fresh-home-categories-bangumi {
|
.fresh-home-categories-bangumi {
|
||||||
@include h-stretch(var(--fresh-home-categories-column-gap));
|
@include h-stretch(var(--fresh-home-categories-column-gap));
|
||||||
|
|||||||
@ -62,6 +62,7 @@
|
|||||||
<div
|
<div
|
||||||
class="fresh-home-categories-bangumi-timeline-season-title"
|
class="fresh-home-categories-bangumi-timeline-season-title"
|
||||||
:title="season.title"
|
:title="season.title"
|
||||||
|
:class="{ today: index === todayIndex }"
|
||||||
>
|
>
|
||||||
{{ season.title }}
|
{{ season.title }}
|
||||||
</div>
|
</div>
|
||||||
@ -98,7 +99,7 @@
|
|||||||
import { DpiImage, VIcon } from '@/ui'
|
import { DpiImage, VIcon } from '@/ui'
|
||||||
import { cssVariableMixin, requestMixin } from './mixin'
|
import { cssVariableMixin, requestMixin } from './mixin'
|
||||||
import { rankListCssVars } from './rank-list'
|
import { rankListCssVars } from './rank-list'
|
||||||
import { setupScrollMask, cleanUpScrollMask } from './scroll-mask'
|
import { setupScrollMask, cleanUpScrollMask } from '../../../scroll-mask'
|
||||||
|
|
||||||
interface TimelineSeason {
|
interface TimelineSeason {
|
||||||
cover: string
|
cover: string
|
||||||
@ -130,7 +131,7 @@ interface TimelineDay {
|
|||||||
const rankListHeight = rankListCssVars.panelHeight - 2 * rankListCssVars.padding
|
const rankListHeight = rankListCssVars.panelHeight - 2 * rankListCssVars.padding
|
||||||
const timelineCssVars = (() => {
|
const timelineCssVars = (() => {
|
||||||
const seasonItemWidth = 250
|
const seasonItemWidth = 250
|
||||||
const seasonTodayWidth = 280
|
const seasonTodayWidth = 250
|
||||||
const timelineItemHeight = 66
|
const timelineItemHeight = 66
|
||||||
const timelineTodayHeight = 96
|
const timelineTodayHeight = 96
|
||||||
const timelineViewportItemsHeight = (
|
const timelineViewportItemsHeight = (
|
||||||
@ -265,7 +266,7 @@ export default Vue.extend({
|
|||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import "common";
|
@import "common";
|
||||||
@import "./effects";
|
@import "../../../effects";
|
||||||
|
|
||||||
.fresh-home-categories-bangumi {
|
.fresh-home-categories-bangumi {
|
||||||
&-timeline {
|
&-timeline {
|
||||||
@ -352,9 +353,10 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
&-seasons-container {
|
&-seasons-container {
|
||||||
@include h-stretch();
|
@include h-stretch();
|
||||||
@include scroll-mask-x();
|
@include scroll-mask-x(18px);
|
||||||
width: 0;
|
width: 0;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
|
margin: 0 2px;
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
&-seasons {
|
&-seasons {
|
||||||
@ -363,7 +365,6 @@ export default Vue.extend({
|
|||||||
overscroll-behavior: initial;
|
overscroll-behavior: initial;
|
||||||
width: 0;
|
width: 0;
|
||||||
flex: 1 0 0;
|
flex: 1 0 0;
|
||||||
margin: 0 2px;
|
|
||||||
scroll-snap-type: x mandatory;
|
scroll-snap-type: x mandatory;
|
||||||
}
|
}
|
||||||
&-season {
|
&-season {
|
||||||
@ -412,6 +413,9 @@ export default Vue.extend({
|
|||||||
grid-area: title;
|
grid-area: title;
|
||||||
@include semi-bold();
|
@include semi-bold();
|
||||||
@include single-line();
|
@include single-line();
|
||||||
|
&.today {
|
||||||
|
@include max-line(2, 1.25);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
&-episode {
|
&-episode {
|
||||||
grid-area: episode;
|
grid-area: episode;
|
||||||
@ -424,7 +428,6 @@ export default Vue.extend({
|
|||||||
@include card(6px);
|
@include card(6px);
|
||||||
@include h-center(4px);
|
@include h-center(4px);
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
font-size: 12px;
|
|
||||||
padding: 2px 4px;
|
padding: 2px 4px;
|
||||||
&.published {
|
&.published {
|
||||||
border-color: var(--theme-color);
|
border-color: var(--theme-color);
|
||||||
@ -435,6 +438,7 @@ export default Vue.extend({
|
|||||||
}
|
}
|
||||||
&-text {
|
&-text {
|
||||||
@include semi-bold();
|
@include semi-bold();
|
||||||
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
&.follow:not(.published) &-icon {
|
&.follow:not(.published) &-icon {
|
||||||
color: var(--theme-color);
|
color: var(--theme-color);
|
||||||
@ -446,10 +450,10 @@ export default Vue.extend({
|
|||||||
height: var(--timeline-today-height);
|
height: var(--timeline-today-height);
|
||||||
--cover-size: 80px;
|
--cover-size: 80px;
|
||||||
grid-template:
|
grid-template:
|
||||||
"cover title title" 1.2fr
|
"cover title title" 2fr
|
||||||
"cover episode episode" 1fr
|
"cover episode episode" 1fr
|
||||||
"cover time ." auto / var(--cover-size) auto 1fr;
|
"cover time ." auto / var(--cover-size) auto 1fr;
|
||||||
row-gap: 8px;
|
row-gap: 4px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -222,7 +222,7 @@ export default Vue.extend({
|
|||||||
</script>
|
</script>
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@import "common";
|
@import "common";
|
||||||
@import "./effects";
|
@import "../../../effects";
|
||||||
|
|
||||||
.fresh-home-video-slides {
|
.fresh-home-video-slides {
|
||||||
@include card(12px);
|
@include card(12px);
|
||||||
|
|||||||
@ -12,7 +12,6 @@ export const setupScrollMask = (config: ScrollMaskConfig) => {
|
|||||||
observers.forEach(o => o.disconnect())
|
observers.forEach(o => o.disconnect())
|
||||||
observersMap.delete(container)
|
observersMap.delete(container)
|
||||||
}
|
}
|
||||||
console.log('setupScrollMask', observersMap)
|
|
||||||
if (items.length === 0) {
|
if (items.length === 0) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user