js上拉載入更多

2021-08-25 19:46:38 字數 3607 閱讀 2707

方法一(jq):

var page = 1, //分頁碼

off_on = false, //分頁開關(滾動載入方法 1 中用的)

timers = null; //定時器(滾動載入方法 2 中用的)

//載入資料

var loadingdatafn = function

() off_on = true; //[重要]這是使用了 時 用到的 !!![如果用 滾動載入方法1 時:off_on 在這裡不設 true的話, 下次就沒法載入了哦!]

};//初始化, 第一次載入

$(document).ready(function

() );

//底部切換

$(document.body).on('click', '#footer div', function

() );

//滾動載入方法1

$('#main').scroll(function

() }

});//滾動載入方法2

$('#main').scroll(function

() , 300);

}});//還可以基window視窗(body)來新增滾動事件, (因為布局不同,所以在這裡沒效果,因為[上面是基於body中的某個元素來新增滾動事的])

$(window).scroll(function

() , 300);

}});

方法二:

//滾動條到頁面底部載入更多案例 

$(window).scroll(function

()else

if(scrolltop<=0)

});

vue上拉載入更多:

lang="html">

class="yo-scroll"

:class=""

@touchstart="touchstart($event)"

@touchmove="touchmove($event)"

@touchend="touchend($event)"

@scroll="(oninfinite || infiniteloading) ? onscroll($event) : undefined">

class="inner"

:style="">

class="pull-refresh">

name="pull-refresh">

class="down-tip">下拉更新span>

class="up-tip">鬆開更新span>

class="refresh-tip">更新中span>

slot>

header>

slot>

class="load-more">

name="load-more">

載入中……span>

slot>

footer>

section>

div>

template>

export default ,

enableinfinite: ,

enablerefresh: ,

onrefresh: ,

oninfinite:

},data()

},methods: ,

touchmove(e)

let diff = e.targettouches[0].pagey - this.starty - this.startscroll

if (diff > 0) e.preventdefault()

this.top = math.pow(diff, 0.8) + (this.state === 2 ? this.offset : 0)

if (this.state === 2)

if (this.top >= this.offset) else

},touchend(e)

if (this.top >= this.offset) else

},refresh() ,

refreshdone() ,

infinite() ,

infinitedone() ,

onscroll(e)

let outerheight = this.$el.clientheight

let innerheight = this.$el.queryselector('.inner').clientheight

let scrolltop = this.$el.scrolltop

let ptrheight = this.onrefresh ? this.$el.queryselector('.pull-refresh').clientheight : 0

let infiniteheight = this.$el.queryselector('.load-more').clientheight

let bottom = innerheight - outerheight - scrolltop - ptrheight

if (bottom < infiniteheight) this.infinite()}}}

script>

.yo-scroll

.yo-scroll

.inner

.yo-scroll

.pull-refresh

.yo-scroll

.touch

.inner

.yo-scroll

.down

.down-tip

.yo-scroll

.up.up-tip

.yo-scroll

.refresh

.refresh-tip

.yo-scroll

.down-tip,

.yo-scroll

.refresh-tip,

.yo-scroll

.up-tip

.yo-scroll

.load-more

style>

上面的相當於乙個vue的元件,可以封裝成乙個成型的外掛程式,**需要**呼叫

on-refresh="onrefresh" :on-infinite="oninfinite">

import scroll from './y-scroll/scroll';

export

default

},mounted : function(),

methods: , (response) => );

},onrefresh

(done) ,

oninfinite

(done) ;

obj["name"] = arr[i].name;

vm.downdata.push(obj);

if((i + 1) >= response.data.length)

}done() // call done

}, (response) => );}},

components :

}script>

js上拉載入更多

jq方法 方法一 var page 1,分頁碼 off on false,分頁開關 滾動載入方法 1 中用的 timers null 定時器 滾動載入方法 2 中用的 載入資料 var loadingdatafn function off on true 重要 這是使用了 時 用到的 如果用 滾動載...

上拉載入更多

在ios開中中,由於螢幕尺寸限制,如果需要顯示的資料很多,需要用到分頁載入。資料來源是個array nsmutablearray items viewcontroller的這個方法返回資料條數 1是為了顯示 載入更多 的那個cell nsinteger tableview uitableview t...

js如何實現上拉載入更多

我們在專案中經常使用到下拉載入更多,之前要麼是底部寫載入按鈕,要麼是引入外掛程式。今天終於有時間手寫乙個了,之前感覺挺麻煩,明白原理後,其實很簡單.scrolltop 滾動視窗的高度距離window頂部的距離,它會隨著往上滾動而不斷增加,初始值是0,它是乙個變化的值 clientheight 它是乙...