Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/infinite-scroll/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ export default {
el[scope] = { el, vm, container, onScroll };

if (container) {
const containerInfo = container.getBoundingClientRect();
if (!containerInfo.width && !containerInfo.height) return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接跳过对隐藏元素的处理的话,当元素变成可见状态的时候,就没法滚动了。

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

谢谢 有道理 已经调整判断位置

container.addEventListener('scroll', onScroll);

if (immediate) {
Expand Down
26 changes: 26 additions & 0 deletions test/unit/specs/infiniteScroll.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,31 @@ describe('InfiniteScroll', () => {
await wait();
expect(vm.$el.innerText.indexOf('2') > -1).to.be.true;
});

it('invisible element not trigger', async() => {
vm = createVue({
template: `
<div v-show="false">
<ul ref="scrollTarget" v-infinite-scroll="load" style="height: 300px;overflow: auto;">
<li v-for="i in count" style="display: flex;height: 50px;">{{ i }}</li>
</ul>
</div>
`,
data() {
return {
count: 0
};
},
methods: {
load() {
this.count += 2;
}
}
}, true);
vm.$refs.scrollTarget.scrollTop = 2000;
await wait();
expect(vm.$el.innerText.indexOf('2') > -1).to.be.false;
});

});