小程序自定義模板實(shí)現(xiàn)吸頂功能
本文實(shí)例為大家分享了小程序?qū)崿F(xiàn)吸頂功能的具體代碼,供大家參考,具體內(nèi)容如下

//如圖所示----這里用了自定義組件實(shí)現(xiàn)了小程序吸頂功能
//WXML
<view class="i-sticky-demo">
<i-sticky scrollTop="{{scrollTop}}">
<i-sticky-item i-class="i-sticky-demo-title">
<view slot="title">
第一層
</view>
<view slot="content" wx:for="{{one}}" wx:key="index">
<view class="i-sticky-demo-item">{{item.name}}</view>
</view>
</i-sticky-item>
<i-sticky-item i-class="i-sticky-demo-title">
<view slot="title">
第二層
</view>
<view slot="content" wx:for="{{two}}" wx:key="index">
<view class="i-sticky-demo-item">{{item.name}}</view>
</view>
</i-sticky-item>
<i-sticky-item i-class="i-sticky-demo-title">
<view slot="title">
第三層
</view>
<view slot="content" wx:for="{{three}}" wx:key="item">
<view class="i-sticky-demo-item">{{item.name}}</view>
</view>
</i-sticky-item>
<i-sticky-item i-class="i-sticky-demo-title">
<view slot="title">
最后
</view>
<view slot="content" wx:for="{{15}}" wx:key="index">
<view class="i-sticky-demo-item">{{index+1}}</view>
</view>
</i-sticky-item>
</i-sticky>
</view>
//json
{
"navigationBarTitleText":"吸頂",
"usingComponents": {
"i-sticky": "../../compont/sticky/index",
"i-sticky-item": "../../compont/sticky-item/index"
}
}
//JS
Page({
data: {
scrollTop: 0,
one: [{
name: "第一層"
}, {
name: "第一層"
}, {
name: "第一層"
}, {
name: "第一層"
}, {
name: "第一層"
}, {
name: "第一層"
}, {
name: "第一層"
}],
two: [{
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}, {
name: "第二層"
}],
three: [{
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}, {
name: "第三層"
}],
},
onChange(event) {
console.log(event.detail, 'click right menu callback data')
},
//頁(yè)面滾動(dòng)執(zhí)行方式
onPageScroll(event) {
this.setData({
scrollTop: event.scrollTop
})
}
});
//WXSS
.i-sticky-demo-item{
width: 100%;
height: 100rpx;
line-height: 100rpx;
padding:0 30rpx;
border-bottom: 1rpx solid #ddd;
}
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
關(guān)于js中e.preventDefault()的具體使用
本文主要介紹了關(guān)于js中e.preventDefault()的具體使用,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04
微信小程序?qū)崿F(xiàn)聯(lián)動(dòng)選擇器
這篇文章主要為大家詳細(xì)介紹了微信小程序?qū)崿F(xiàn)聯(lián)動(dòng)選擇器,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02
JavaScript中Number.isNaN 和 isNaN 的區(qū)別詳解
本文和大家分享一個(gè)前幾天寫(xiě)代碼踩的坑,筆者在業(yè)務(wù)邏輯中需要對(duì)一個(gè)值進(jìn)行NaN的判斷,由于筆者的不嚴(yán)謹(jǐn),使用了isNaN,從而引起B(yǎng)ug,也正是因?yàn)檫@個(gè),筆者才知道了isNaN和Number.isNaN的區(qū)別,所以本文就和大家聊聊它們的區(qū)別2023-09-09
JavaScript輕松創(chuàng)建級(jí)聯(lián)函數(shù)的方法示例
級(jí)聯(lián)函數(shù)也叫鏈?zhǔn)胶瘮?shù),方法鏈一般適合對(duì)一個(gè)對(duì)象進(jìn)行連續(xù)操作 (集中在一句代碼)。一定程度上可以減少代碼量,缺點(diǎn)是它占用了 函數(shù)的返回值。下面這篇文章主要給大家介紹了利用JavaScript如何輕松創(chuàng)建級(jí)聯(lián)函數(shù)的方法示例,需要的朋友可以參考借鑒。2017-02-02
JavaScript中的函數(shù)聲明和函數(shù)表達(dá)式區(qū)別淺析
這篇文章主要介紹了JavaScript中的函數(shù)聲明和函數(shù)表達(dá)式區(qū)別淺析,本文總結(jié)的淺顯易懂,非常好的一篇技術(shù)文章,需要的朋友可以參考下2015-03-03
利用d3.js實(shí)現(xiàn)蜂巢圖表帶動(dòng)畫(huà)效果
這篇文章主要給大家介紹了關(guān)于如何利用d3.js實(shí)現(xiàn)蜂巢圖表帶動(dòng)畫(huà)效果的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用d3.js具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
fullPage.js和CSS3實(shí)現(xiàn)全屏滾動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了fullPage.js和CSS3實(shí)現(xiàn)全屏滾動(dòng)效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-05-05
BootstrapTable請(qǐng)求數(shù)據(jù)時(shí)設(shè)置超時(shí)(timeout)的方法
使用bootstrapTable獲取數(shù)據(jù)時(shí),有時(shí)由于網(wǎng)絡(luò)或者服務(wù)器的原因,無(wú)法及時(shí)獲取到數(shù)據(jù),頁(yè)面顯示一直處于等待狀態(tài)。為了改善效果,考慮設(shè)置超時(shí),請(qǐng)求發(fā)送后超時(shí)即顯示無(wú)數(shù)據(jù),過(guò)段時(shí)間重新發(fā)起請(qǐng)求2017-01-01

