小さなプログラム ナビゲーション バーをクリックして先頭に戻ります 小さな例

ここに画像の説明を挿入

<view class="headerTop"  id="headerTop" @click="onNavigationBarTap">
	顶部导航栏
</view>
//样式
width: 100%;
position: fixed;
background: white;
left: 0;
z-index: 999;
//js
 lastTapTime: null,//用于记录上一次点击的时间戳
 screenHeight: 0//高度设置为0
onLoad(){
    
    
	//获取屏幕高度
	const systemInfo = uni.getSystemInfoSync();
	this.screenHeight = systemInfo.windowHeight;
},
methods:{
    
    
	//在导航栏上添加一个@click事件的监听函数,判断两次点击的时间间隔是否小于300ms,如果是,则认为是双击事件,执行页面滚动到顶部的操作。
			onNavigationBarTap(event){
    
    
				 const currentTimeStamp = event.timeStamp;
				 const lastTimeStamp = this.lastTapTime || 0;
				 const timeDiff = currentTimeStamp - lastTimeStamp;
				 if (timeDiff < 300) {
    
     // 双击事件
				     uni.pageScrollTo({
    
    
				     scrollTop: 0,
				     duration: 300
				   });
				 }
				  this.lastTapTime = currentTimeStamp;
			},
}

おすすめ

転載: blog.csdn.net/qq_47272950/article/details/130701030