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
}
}
天蓬老师2017-05-19 10:36:54
You can use custom instructions to implement, Demo:
https://jsfiddle.net/fedesign...
给我你的怀抱2017-05-19 10:36:54
scrollTop
和offsetTop
都是变量。
你要不绑定scroll
事件的时候把body
的scrollTop
和所有需要的p
的offsetTop
都获取下存到data
里?
Then
<p ref='pBox'>
<p v-show='bodyScrollTop === offsetTop.p1'>这是一个段落1</p>
<p v-show='bodyScrollTop === offsetTop.p2'>这是一个段落2</p>
<p v-show='bodyScrollTop === offsetTop.p3'>这是一个段落3</p>
</p>
However, I have some doubts about the effect, that is, when several p
s are not displayed, their offsetTop
s have the same value. p
未显示的时候他们的offsetTop
是不是同一个值。
然后我想知道你的p
Then I want to know what your p
node refers to? Text node?
我想大声告诉你2017-05-19 10:36:54
document.querySelector('p').childen
document.getElementByTagName('p')[0].childen
给我你的怀抱2017-05-19 10:36:54
Thank you for your answers, the final solution is:
// animated bounceIn 为animated.css里的
<section class="newBlog" v-scroll-show>
<p class="title animated bounceIn">
<p class="headline">最近更新</p>
</p>
<p class="posts">
<p>文章</p>
</p>
</section>
.title, .posts {
display: none;
}
directives: {
scrollShow: {
bind: (el) => {
window.addEventListener('scroll', () => {
if (document.body.scrollTop + 400 > el.offsetTop) {
for (let i = 0; i < el.children.length; i++) {
setTimeout(() => {
el.children[i].style.display = 'block'
}, 1000 * i)
}
}
})
}
}
}