fix(Calendar): should update header title

This commit is contained in:
陈嘉涵 2019-12-25 16:03:02 +08:00 committed by neverland
parent bfb08c37cb
commit 51c4dc180b

View File

@ -99,20 +99,27 @@ export default createComponent({
}, },
onScroll() { onScroll() {
const scrollTop = getScrollTop(this.$refs.body); const { body, months } = this.$refs;
const monthsHeight = this.$refs.month.map(item => item.height); const top = getScrollTop(body);
const bodyTop = scrollTop; const bottom = top + this.bodyHeight;
const bodyBottom = scrollTop + this.bodyHeight; const heights = months.map(item => item.height);
let height = 0; let height = 0;
let firstMonth;
for (let i = 0; i < this.months.length; i++) { for (let i = 0; i < months.length; i++) {
const monthTop = height; const visible = height <= bottom && height + heights[i] >= top;
const monthBottom = height + monthsHeight[i];
const visible = monthTop <= bodyBottom && monthBottom >= bodyTop;
this.$refs.month[i].visible = visible; if (visible && !firstMonth) {
firstMonth = months[i];
}
height += monthsHeight[i]; months[i].visible = visible;
height += heights[i];
}
if (firstMonth) {
this.monthTitle = firstMonth.title;
} }
}, },
@ -151,7 +158,7 @@ export default createComponent({
genMonth(date, index) { genMonth(date, index) {
return ( return (
<Month <Month
ref="month" ref="months"
refInFor refInFor
type={this.type} type={this.type}
date={date} date={date}