最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

微信小程序實現(xiàn)簡單吸頂效果

 更新時間:2022年01月17日 09:15:40   作者:qq_36437172  
這篇文章主要為大家詳細介紹了微信小程序實現(xiàn)簡單吸頂效果,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了微信小程序實現(xiàn)吸頂效果的具體代碼,供大家參考,具體內容如下

吸頂效果思路:

1.首先獲取 Tab 欄與頂部的距離;

2.監(jiān)聽頁面滾動事件 onPageScroll,判斷 Tab 欄是否滾動到頂部;

3.當 Tab 欄滾動到頂部時,添加吸頂樣式,實現(xiàn)效果。

Page({
? data: {
? ? navbarInitTop: 0, //導航欄初始化距頂部的距離
? ? isFixedTop: false, //是否固定頂部
? },
?
? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面加載
? ?*/
? onLoad: function(options) {
?
? },
?
? /**
? ?* 生命周期函數(shù)--監(jiān)聽頁面顯示
? ?*/
? onShow: function() {
? ? var that = this;
? ? if (that.data.navbarInitTop == 0) {
? ? ? //獲取節(jié)點距離頂部的距離
? ? ? wx.createSelectorQuery().select('#navbar').boundingClientRect(function(rect) {
? ? ? ? if (rect && rect.top > 0) {
? ? ? ? ? var navbarInitTop = parseInt(rect.top);
? ? ? ? ? that.setData({
? ? ? ? ? ? navbarInitTop: navbarInitTop
? ? ? ? ? });
? ? ? ? }
? ? ? }).exec();
?
? ? }
? },
?
? /**
? ?* 監(jiān)聽頁面滑動事件
? ?*/
? onPageScroll: function(e) {
? ? var that = this;
? ? var scrollTop = parseInt(e.scrollTop); //滾動條距離頂部高度
? ? //判斷'滾動條'滾動的距離 和 '元素在初始時'距頂部的距離進行判斷
? ? var isSatisfy = scrollTop >= that.data.navbarInitTop ? true : false;
? ? // 只有處于吸頂?shù)呐R界值才會不相等
? ? if (that.data.isFixedTop === isSatisfy) {
? ? ? return false;
? ? }
?
? ? that.setData({
? ? ? isFixedTop: isSatisfy
? ? });
? }
})

代碼部分

<view style="width: 90%; height: 300rpx; background: #f0f0f0; margin: 30rpx auto;"></view>
<view style="width: 90%; height: 300rpx; background: #f0f0f0; margin: 30rpx auto;"></view>
?
<view class="navbar-wrap">
? <view class="column {{isFixedTop?'fixed':''}}" id="navbar">
? ? <view class="block active">新品推薦</view>
? ? <view class="block">限時優(yōu)惠</view>
? ? <view class="block">火爆熱搜</view>
? ? <view class="block">猜你喜歡</view>
? </view>
? <!-- 用于吸頂后 占位用的 -->
? <view class="column" wx:if="{{isFixedTop}}"></view>
</view>
?
<block wx:for="{{20}}" wx:key="list">
? <view style="width: 100%; height: 120rpx; background: #f0f0f0; margin: 20rpx auto;"></view>
</block>

頁面樣式:

view, text {
? box-sizing: border-box;
? -moz-box-sizing: border-box;
? -webkit-box-sizing: border-box;
}
?
.navbar-wrap {
? width: 100%;
}
?
.navbar-wrap .column {
? width: 100%;
? height: 80rpx;
? display: flex;
? flex-direction: row;
? align-items: center;
? justify-content: space-around;
? background: #fff;
? border-bottom: solid 1px #eee;
?
? top: 0;
? left: 0;
? z-index: 100;
}
?
.navbar-wrap .column.fixed {
? position: fixed;
}
?
/* 以下的代碼不重要 */
?
.navbar-wrap .column .block {
? width: 25%;
? height: 80rpx;
? line-height: 80rpx;
? text-align: center;
? font-size: 30rpx;
? color: #333;
? letter-spacing: 1px;
? position: relative;
}
?
.navbar-wrap .column .block::after {
? content: "";
? width: 60%;
? height: 3px;
? border-radius: 2px;
? position: absolute;
? bottom: 0;
? left: 50%;
? transform: translateX(-50%);
? background: transparent;
}
?
.navbar-wrap .column .block.active {
? color: #1490ce;
? font-weight: bold;
}
?
.navbar-wrap .column .block.active::after {
? background: linear-gradient(160deg, rgba(8, 220, 230, 0.7) 10%, rgba(0, 140, 255, 0.7) 90%);
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論

浪卡子县| 遂川县| 根河市| 吉林市| 延川县| 八宿县| 孝感市| 葫芦岛市| 湄潭县| 睢宁县| 神农架林区| 革吉县| 鄂伦春自治旗| 栾川县| 石屏县| 宁安市| 团风县| 靖边县| 冀州市| 云霄县| 大新县| 凤山县| 铜川市| 杭锦后旗| 天祝| 白山市| 微博| 房产| 曲阳县| 门源| 买车| 柞水县| 汉中市| 大荔县| 犍为县| 祁东县| 定远县| 三江| 江口县| 驻马店市| 竹溪县|