How to get node in html tag?
曾经蜡笔没有小新
曾经蜡笔没有小新 2017-05-19 10:34:54
0
4
772

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
    }
}
曾经蜡笔没有小新
曾经蜡笔没有小新

reply all(4)
Peter_Zhu

You can use custom instructions to implement, Demo:
https://jsfiddle.net/fedesign...

给我你的怀抱

scrollTopoffsetTop都是变量。
你要不绑定scroll事件的时候把bodyscrollTop和所有需要的poffsetTop都获取下存到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 ps are not displayed, their offsetTops have the same value. p未显示的时候他们的offsetTop是不是同一个值。
然后我想知道你的pThen I want to know what your p node refers to? Text node?

我想大声告诉你
document.querySelector('p').childen
document.getElementByTagName('p')[0].childen
给我你的怀抱

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)
                        }
                    }
                })
            }
        }
    }
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template