微信小程序?qū)崿F(xiàn)監(jiān)聽頁面滾動(dòng)
本文實(shí)例為大家分享了微信小程序?qū)崿F(xiàn)監(jiān)聽頁面滾動(dòng)的具體代碼,供大家參考,具體內(nèi)容如下
1.正常狀態(tài)下
2.頁面滾動(dòng)到大于100時(shí)顯示定位到頂部的view盒子
3.html部分
<view class="question"> ? <!-- 頂部Banner圖 --> ? <view class="qBanner" > ? ? <image class="qBannera" src="../../../images/question/banner.png" alt=""></image> ? ? <image class="qBesc" src="../../../images/question/esc.png" alt="" bindtap="esc"></image> ? ? <text class="qBtxt">問答</text> ? ? <view class="sousuo"> ? ? ? <image src="../../../images/question/sousuo.png"></image> ? ? ? <input type="text" placeholder="搜索" value="{{ value }}" bind:change="onChange" bindconfirm="search" /> ? ? </view> ? </view> ? <!-- 定位 --> ? <view class="fix" wx:if="{{fixs == 0}}"> ? ? <image ?src="../../../images/question/escs.png" alt="" bindtap="esc"></image> ? ? <view> ? ? ? <image src="../../../images/question/sousuo.png"></image> ? ? ? <input type="text" placeholder="搜索" value="{{ value }}" bind:change="onChange" bindconfirm="search" /> ? ? </view> ? </view> </view>
4.js部分
Page({ ? ? data: { ? ? ? ? fixs:1 ? ? }, ? ? // 監(jiān)聽頁面 ? ? onPageScroll(e) { ? ? ? ? console.log(e.scrollTop) ? ? ? ? if(e.scrollTop > 100){ ? ? ? ? ? this.setData({ ? ? ? ? ? ? fixs: 0 ? ? ? ? ? }); ? ? ? ? } else { ? ? ? ? ? this.setData({ ? ? ? ? ? ? fixs: 1 ? ? ? ? ? }); ? ? ? ? } ? ? }, })
5.css部分
/* 總盒子 */ .question{ ? width: 100%; ? background: #F4F4F7; ? position: relative; } /* 頂部banner盒子 */ .qBanner{ ? width: 100%; ? height: 454rpx; ? position: relative; } /* 背景圖 */ .qBannera{ ? width: 100%; ? height: 100%; } /* 自定義導(dǎo)航欄返回按鈕 */ .qBesc{ ? width: 34rpx; ? height: 34rpx; ? position: absolute; ? top: 114rpx; ? left: 54rpx; } /* 自定義導(dǎo)航欄標(biāo)題 */ .qBtxt{ ? width: 72rpx; ? height: 50rpx; ? font-size: 36rpx; ? font-family: PingFangSC-Medium, PingFang SC; ? font-weight: 500; ? color: #232326; ? position: absolute; ? top: 108rpx; ? left: 46%; ? /* transform: translate(-0.01%,-50%); */ } /* 搜索盒子 */ .sousuo{ ? position: absolute; ? top: 186rpx; ? left: 58rpx; ? background: #FFFFFF; ? width: 640rpx; ? height: 72rpx; ? border: 2rpx solid #EFF0F4; ? border-radius: 36rpx; } .sousuo image{ ? position: absolute; ? width: 28rpx; ? height: 28rpx; ? top: 20rpx; ? left: 20rpx; } .sousuo input{ ? width: 90%; ? height: 100%; ? margin-left: 60rpx; } /* 滾動(dòng)導(dǎo)航欄定位 */ .fix{ ? width: 100%; ? height: 176rpx; ? background: #876BF4; ? position: fixed; ? top: 0; ? left: 0; ? display: flex; ? justify-content: flex-start; ? align-items: flex-end; } .fix image{ ? width: 34rpx; ? height: 34rpx; ? margin-left: 54rpx; ? margin-bottom: 27rpx; } .fix view{ ? width: 384rpx; ? height: 72rpx; ? margin-bottom: 8rpx; ? margin-left: 62rpx; ? position: relative; ? background: #FFFFFF; ? border-radius: 38rpx; ? border: 2rpx solid #EFF0F4; ? overflow: hidden; } .fix view input{ ? width: 83%; ? height: 100%; ? float: right; } .fix view image{ ? position: absolute; ? top: 20rpx; ? left: -30rpx; ? width: 28rpx; ? height: 28rpx; } .input-placeholder{ ? font-size: 28rpx; ? font-family: PingFang-SC-Regular, PingFang-SC; ? font-weight: 400; ? color: #D2D2D5; }
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript實(shí)現(xiàn)列表分頁功能特效
最近在做一個(gè)小項(xiàng)目,有時(shí)需要制作靜態(tài)頁面網(wǎng)站,而一旦涉及到文章的分頁,實(shí)現(xiàn)起來非常麻煩,自己又剛?cè)腴T,對js不是很熟悉,所以就拿來練練手。2015-05-05webpack5的loader配置小白學(xué)習(xí)篇
這篇文章主要為大家介紹了webpack5的loader配置非常適合webpack入門的小白學(xué)習(xí),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-05-05ie支持function.bind()方法實(shí)現(xiàn)代碼
在 google 一番技術(shù)資料后,發(fā)現(xiàn) firefox 原生支持一個(gè) bind 方法,該方法很好的滿足了我們的初衷,調(diào)用方法與 call 和 apply 一樣,只是定義完成后,在后期調(diào)用時(shí)該方法才會(huì)執(zhí)行,需要的朋友可以了解下2012-12-12微信小程序swiper組件用法實(shí)例分析【附源碼下載】
這篇文章主要介紹了微信小程序swiper組件用法,結(jié)合實(shí)例形式分析了微信小程序中swiper組件的功能、使用方法,并附帶完整源碼供讀者下載參考,需要的朋友可以參考下2017-12-12JavaScript實(shí)現(xiàn)氣球打字的小游戲
這篇文章主要介紹了JavaScript實(shí)現(xiàn)氣球打字的小游戲,下面文章的思路來源于打字游戲,具體實(shí)現(xiàn)過程,需要的朋友可以參考一下,希望對你的學(xué)習(xí)有所幫助2022-04-04js實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡單實(shí)例
下面小編就為大家?guī)硪黄猨s實(shí)現(xiàn)目錄鏈接,內(nèi)容跟著目錄滾動(dòng)顯示的簡單實(shí)例。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2016-10-10