zoukankan      html  css  js  c++  java
  • uniapp吸顶功能

    <template>
    	<view class="about">		
    		<view class="lis">			
    			 <view class="li" v-for="(item,index) in 100" :key="index">
    				{{index}}
    			 </view>
    		</view>
    		<!-- :style="{top:topHeight+'upx'}" -->
    		 <view :class="[(isFixedTop) ? 'fixedTop' : '']" id="box" class="box">
    		 	吸顶导航
    		 </view>
    		 <view class="lis">
    		 	 <view class="li" v-for="(item,index) in 50" :key="index">
    		 		{{index}}
    		 	 </view>
    		 </view>
    	</view>
    </template>
    
    <script>
    	export default {
    		data() {
    			return {
    				isFixedTop:false,
    				Topdistance:3000,
    				topHeight:"",
    			}
    		},
    		onLoad() { 
    			uni.pageScrollTo({
    				scrollTop:0,
    				duration:0
    			})
    			setTimeout(()=>{
    				this.GetTop()
    				// this.aaa()
    			},1000)
    		},
    		onPageScroll(e) {
    			console.log(e.scrollTop)
    			if(e.scrollTop > this.Topdistance){
    				this.isFixedTop=true
    			}else{
    				this.isFixedTop=false
    			}
    		},
    		methods: { 
    			aaa(){			 
    				uni.createSelectorQuery().in(this).select('.uni-page-head').boundingClientRect(result => {
    					 if (result) { 
    						this.topHeight=result.height * 2
    						console.log(this.topHeight)
    					}else { 
    						 
    					} 
    				 }).exec(); 			 
    			},	
    			GetTop(){
    				//获取元素距离顶部的距离
    				var _this=this
    				uni.getSystemInfo({
    					success:(resu)=>{	
    						console.log(resu)
    						const query = uni.createSelectorQuery()
    						query.select('#box').boundingClientRect()
    						query.selectViewport().scrollOffset()
    						query.exec(function(res){
    							_this.Topdistance=res[0].top
    							console.log(res)
    						})
    					},
    					fail:(res)=>{}
    				})
    			}, 
    			
    		}
    		
    	}
    </script>
    
    <style>
    	 .li{
    		 height: 100upx;
    		 line-height: 100upx;
    		 margin-top: 20upx;
    		 text-align: center;
    		 color: #FFFFFF;
    	 }
    	 .lis :nth-child(3n+1){
    		 opacity: 0.1;
    		 background-color: #f00;
    	 }
    	 .lis :nth-child(3n+2){
    		  opacity: 0.1;
    	 	 background-color: #0f0;
    	 }
    	 .lis :nth-child(3n+3){
    		  opacity: 0.1;
    	 	 background-color: #00f;
    	 }
    	 .box{
    		 height: 100upx;
    		 line-height: 100upx; 
    		 text-align: center;
    		 background-color: #f0f;
    		 color: #fff;
    	 }
    	 .fixedTop{
    		 position: fixed;
    		 top:0;
    		 left: 0;
    		 right: 0;
    		 z-index: 9999999;
    	 }
    </style>
    

      

  • 相关阅读:
    base 镜像
    最小的镜像
    Docker 组件如何协作?- 每天5分钟玩转容器技术(8)
    Docker 架构详解
    容器 What, Why, How
    【视频或者图文】运行第一个容器
    运行第一个容器
    [原]关于helios自定义面板简述
    [osg]osg背景图设置
    [qt]qstring和string中文支持转换问题
  • 原文地址:https://www.cnblogs.com/daifuchao/p/13647044.html
Copyright © 2011-2022 走看看