I’m struggling to find a solution that allows me to update the following code to include additional classes. E.g. in addition to .section–bg1, I’d like to include .section–bg2. and .section–bg3.
For further context, here’s a Fiddle:
How can I include the red coloured background section (.section–bg2) in the JavaScript?
I’ve tried “el.classList.contains('section--bg1', 'section--bg2');
” but that is not working. What am I missing?
// active section
if ( (sectionTop <= replaceItemBottom) && (sectionBottom > replaceItemTop)) {
// check if current section has bg
currentSection = el.classList.contains('section--bg1');
// switch class depending on background image
if ( currentSection ) {
replaceContainer[0].classList.remove('js-replace--reverse');
} else {
replaceContainer[0].classList.add('js-replace--reverse')
}
}