<script src="libs/vue.js"></script>
<link rel="stylesheet" href="libs/element/index.css">
<script src="libs/element/index.js"></script>
<script src="libs/jquery-3.6.0.min.js"></script>
<style>
.test1-enter-active {
animation: test1-play 2s;
}
@keyframes test1-play {
0% {
margin-top: 50px;
}
100% {
margin-top: 5px;
}
}
</style>
<div id="app">
<el-container>
<el-header>
<el-row type="flex" class="row-bg" justify="center" style="border: 1px solid blue;">
<div>
<h1>头部</h1>
</div>
</el-row>
</el-header>
<el-main>
<el-row>
<div style="border: 1px solid red;height: 700px">
<div style="text-align: center">
<h1>哈哈,这是满格第一屏</h1>
</div>
</div>
</el-row>
<el-row type="flex" justify="center" style="margin-top: 20px">
<el-col :span="20">
<div style="border: 1px solid red;height: 500px">
哈哈,这是第二屏
</div>
</el-col>
</el-row>
<el-row type="flex" justify="center" style="margin-top: 20px">
<el-col :span="18">
<transition-group name="test1" tag="p" id="item2">
<div style="width: 100%; height: 100px;border: 1px solid blue; margin-top:5px;" v-for="item in items2" v-bind:key="item.id">
{{ item.text }}123
</div>
</transition-group>
</el-col>
</el-row>
</el-main>
<el-footer>
<el-row type="flex" justify="center" style="margin-top: 20px">
底部内容
</el-row>
</el-footer>
</el-container>
</div>
new Vue({
el: '#app',
data: {
items: [],
isShow: false,
item1Play: false,
items2: [],
items2Data: [{
id: '1',
text: 'aaaaa'
},
{
id: '2',
text: 'bbbbb'
},
{
id: '3',
text: 'ccccc'
},
{
id: '4',
text: 'ddddd'
},
{
id: '5',
text: 'eeeee'
},
{
id: '6',
text: 'fffff'
},
{
id: '7',
text: 'ggggg'
},
{
id: '8',
text: 'wwwww'
},
]
},
created() {
window.onscroll = () => {
this.scroll();
}
},
methods: {
getScrollTop() {
let scrollPos;
if (window.pageYOffset) {
scrollPos = window.pageYOffset;
} else if (document.compatMode && document.compatMode != 'BackCompat') {
scrollPos = document.documentElement.scrollTop;
} else if (document.body) {
scrollPos = document.body.scrollTop;
}
return scrollPos;
},
scroll() {
let scrollPos = this.getScrollTop();
console.log("scrollPos:", scrollPos);
if (scrollPos == 0) {
}
this.listenerScroll1(scrollPos);
},
listenerScroll(scrollPos) {
let item1TopHeight = $("#item1").offset().top;
let lookHeight = $(window).height();
if ((scrollPos + lookHeight) > item1TopHeight) {
console.log('进来屏幕了');
this.item1Play = true;
}
},
listenerScroll1(scrollPos) {
let item2TopHeight = $("#item2").offset().top;
let item2Height = $("#item2").height();
let lookHeight = $(window).height();
if ((scrollPos + lookHeight) > item2TopHeight + item2Height) {
console.log('滚动到item2的底部了');
this.appendItem2();
}
},
appendItem2() {
if (this.items2.length < this.items2Data.length) {
this.items2.push(this.items2Data[this.items2.length])
}
},
}
})