简体   繁体   中英

ScrollMagic cancels pseudo-selectors

I'm trying to use ScrollMagic library to use "Section Wipes" effect and i apply a color for every second div, using nth-child(even) but it doesn't seem to work with ScrollMagic. All boxes become white Html:

    <div class="box" data="box-1"></div>
    <div class="box" data="box-2"></div>
    <div class="box" data="box-3"></div>
    <div class="box" data="box-4"></div>
    <div class="box" data="box-5"></div>

Css:

.box {
  width: 100%;
  height: 100vh;
  display: grid;
  place-items: center;   
}

.box:nth-child(even) {
  background-color: #ccc;
}

Javascript:

let boxes = document.querySelectorAll('.box');



let controller = new ScrollMagic.Controller({
    globalSceneOptions: {
        triggerHook: 'onLeave',
    }
});


for (let i = 0; i < boxes.length; i++) {
    new ScrollMagic.Scene({
        triggerElement: boxes[i]
    })
    .setPin(boxes[i], )
    .addTo(controller);
}

.box:nth-child(even) won't work because .box elements are not siblings anymore, they get wrapped by .scrollmagic-pin-spacer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM