您好,登錄后才能下訂單哦!
JavaScript中怎么實(shí)現(xiàn)列表向上無(wú)限滾動(dòng),相信很多沒(méi)有經(jīng)驗(yàn)的人對(duì)此束手無(wú)策,為此本文總結(jié)了問(wèn)題出現(xiàn)的原因和解決方法,通過(guò)這篇文章希望你能解決這個(gè)問(wèn)題。
html
<p class="transdata1"> <ul class="tody-table-header2"> <li>商品</li> <li>數(shù)量(kg)</li> <li>單價(jià)(元)</li> <li>金額(元)</li> </ul> <p id="detetion-box2"> <p id="detetion-con1"> <ul v-for="(item,index) in todayDetetion2" :key="index"> <li>{{item.name}}</li> <li>{{item.amount}}kg</li> <li>{{item.price}}元/kg</li> <li >{{item.money}}元</li> </ul> </p> <p id="detetion-con2"></p> </p></p>
js
getData() { var _this = this; this.$axios .get("請(qǐng)求的url") .then(res => { this.todayDetetion2 = res.data.data; this.$nextTick(() => { this.ScrollUp2(); }); }) .catch(err => {}); }, ScrollUp2() { var box = document.getElementById("detetion-box2"); var con1 = document.getElementById("detetion-con1"); var con2 = document.getElementById("detetion-con2"); this.speed = 50; if (con1.offsetHeight >= box.offsetHeight) { con2.innerHTML = con1.innerHTML; var timer1 = setInterval(scrol, this.speed); function scrol() { /*判斷滾動(dòng)內(nèi)容是否已經(jīng)滾完,滾完了則滾動(dòng)的值重新設(shè)置到0,否則就每個(gè)30默秒向上滾動(dòng)1px */ if (box.scrollTop >= con1.scrollHeight) { box.scrollTop = 0; } else { box.scrollTop++; } /*判斷滾動(dòng)的距離剛好為一條公告的高度時(shí)停掉定時(shí)器,隔1s之后重新啟動(dòng)計(jì)時(shí)器即可實(shí)現(xiàn)公告滾動(dòng)停留效果 */ if (box.scrollTop % 25 == 0) { clearInterval(timer1); setTimeout(() => { timer1 = setInterval(scrol, 30); }, 2000); } } } }
css(樣式自己調(diào))
.transdata1 { background: url("../../../static/img/transdata_bg.png") no-repeat center/100% 100%; height: 237px; padding: 36px 28px 16px 20px; box-sizing: border-box; transform: translateY(-12px);}.tody-table-header2 { overflow: hidden;}.tody-table-header2 li { height: 24px; width: 82px; line-height: 24px; list-style: none; float: left; font-size: 13px; margin-right: 48px; font-family: MicrosoftYaHei; color: rgba(127, 250, 255, 1); text-align: center; background: url("../../../static/img/thead_bg.png") no-repeat center/100%; background-size: 100% 100%;}.tody-table-header2 li:last-child { margin-right: 0;}#detetion-box2 { margin-top: 13px; height: 150px; overflow: hidden;}#detetion-box2 ul { overflow: hidden; border-bottom: 1px solid #0e579c;}#detetion-box2 li { width: 82px; height: 24px; line-height: 24px; float: left; margin-right: 48px; font-size: 12px; color: #fff;}#detetion-box2 ul li:last-child { margin-right: 0;}
看完上述內(nèi)容,你們掌握J(rèn)avaScript中怎么實(shí)現(xiàn)列表向上無(wú)限滾動(dòng)的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀(guān)點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。