uni-app实现锚点定位功能

效果图

锚点功能

功能实现

使用uni-app自带scroll-view组件利用scroll-into-view属性来自定滚动到的子元素的id,从而实现锚点功能。需要注意的地方有scroll-view需要指定高度,利用css来指定高度。

代码

<view class="service_item_list">
	<u-tabs ref="tabs" font-size="30"  :list="serviceList" :show-bar="true" :current="current" 
	 bar-width="40" activeFontColor="#333333" active-color="#43B6BB"  @change="changeTab"></u-tabs>
	<scroll-view :scroll-into-view="toView" :style="contentStyle" :show-bar="false" :scroll-y="true" :scroll-with-animation="true" class="service_item_content">	
		<view class="md" id="md1"  v-html="serviceInfo.cont"></view>
		<view class="md" id="md2"  v-html="serviceInfo.notice"></view>
		<view class="md" id="md3"  v-html="serviceInfo.costExplain"></view>
		<view class="md" id="md4"  v-html="serviceInfo.refundExplain"></view>
		</scroll-view>
</view>

changeTab(resIndex) {
	this.current = resIndex
	this.toView = 'md' + (resIndex + 1)
	this.rotateAndScale()
},
		data() {
			return {
				animationData: {},
				animation: null,
			}
		},
		methods: {
			changeTab(resIndex) {
				this.current = resIndex
				this.rotateAndScale()
			},
			// 定义动画内容
			rotateAndScale() {
				// 定义动画内容
				this.animation.rotate(45).scale(2, 2).step()
				// 导出动画数据传递给data层
				this.animationData = this.animation.export()
			},
			norotateAndScale() {
				this.animation.rotate(0).scale(1, 1).step()
				this.animationData = this.animation.export()
			},
		},
		onShow: function() {
			var animation = uni.createAnimation({
				duration: 1000,
				timingFunction: 'ease',
			})
			this.animation = animation
		}
	}
</script>

  • 0
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值