If you use a click event, you can use event to find out the current node.
However, if the event is not bound, how to obtain the current p node in the p tag
<p>这是一个段落</p>
My requirement is that when scrolling to different nodes through the scroll bar, v-show=true
<p ref='pBox'>
<p v-show='body.scrollTop === 当前节点.offsetTop'>这是一个段落1</p>
<p v-show='body.scrollTop === 当前节点.offsetTop'>这是一个段落2</p>
<p v-show='body.scrollTop === 当前节点.offsetTop'>这是一个段落3</p>
</p>
export default {
computed: {
body: this.$refs.pBox.offsetParent
}
}
You can use custom instructions to implement, Demo:
https://jsfiddle.net/fedesign...
scrollTop
和offsetTop
都是变量。你要不绑定
scroll
事件的时候把body
的scrollTop
和所有需要的p
的offsetTop
都获取下存到data
里?Then
However, I have some doubts about the effect, that is, when several
p
s are not displayed, theiroffsetTop
s have the same value.p
未显示的时候他们的offsetTop
是不是同一个值。然后我想知道你的
p
Then I want to know what yourp
node refers to? Text node?Thank you for your answers, the final solution is: