Carlos Aguni

Highly motivated self-taught IT analyst. Always learning and ready to explore new skills. An eternal apprentice.


Vuejs custom sticky

12 Oct 2022 »
window.addEventListener('scroll', (e) => {
    // console.log('obj', obj.$refs.cm)
    // console.log(mk.getBoundingClientRect())
    let cm = obj.$refs.cm.$el
    let bb = cm.getBoundingClientRect()
    // console.log('---', bb.top, mk.getBoundingClientRect().top)
    if (!window.bb){
        window.bb = bb
    }
    if (bb.top < 0) {
        cm.style.position = 'fixed'
        cm.style.top = '10px'
        cm.style.width = bb.width+'px'
    }else if (bb.top < mk.getBoundingClientRect().top){
        cm.style.position = 'inherit'
        cm.style.top = '10px'
        // cm.style.width = bb.width+'px'
    }
})