我是左右滑动

原理是@scroll,直接上代码

template

<div id="wechats" class="wechat-list" @scroll="scrollChange()">
     <div class="wechat“>你的内容</div>
     <div id="chooseBtn" class="wechats-button">你的图标</div>
</div>

js

scrollChange () {
	console.log('scrollChange')
	let scw = document.getElementById('wechats').clientWidth
	let sw = document.getElementById('wechats').scrollWidth
	let sl = document.getElementById('wechats').scrollLeft
	if (sw > scw) {
		document.getElementById('chooseBtn').style.marginRight = -sl + 'px'
	} else {
		document.getElementById('chooseBtn').style.marginRight = 0 + 'px'
	}
}
Logo

前往低代码交流专区

更多推荐