Bootstrap radio buttons are being utilized.
I want the animation to change when one of these buttons is selected.
I am currently working on changing colors in JavaScript. I attempted to use a for each loop but encountered errors stating that it is not a function or undefined when trying to display a color.
const showcase = document.querySelector('.showcase');
const black = document.querySelector('#black');
const white = document.querySelector('#white');
const grey = document.querySelector('#grey');
const yellow = document.querySelector('#yellow');
const colorChoice = document.getElementById
let colors = [colorChoice];
console.log(colors);
// load events
loadEventListeners();
// size and color events
function loadEventListeners() {
color.addEventListener('click', colorChange);
}
// color change
function colorChange(e) {
colors.forEach(function(color) {
if (color = black) {
console.log(color)
console.log('black')
showcase.style.animation = 'blackjacket 6s infinite';
showcase.style.animationTimingFunction = 'steps(1, end)';
} else if (color = white) {
console.log('white')
showcase.style.animation = 'whitejacket 6s infinite';
showcase.style.animationTimingFunction = 'steps(1, end)';
} else if (color = grey) {
console.log('grey')
showcase.style.animation = 'greyjacket 6s infinite';
showcase.style.animationTimingFunction = 'steps(1, end)';
} else if (color = yellow) {
console.log('yellow')
showcase.style.animation = 'yellowjacket 6s infinite';
showcase.style.animationTimingFunction = 'steps(1, end)';
} else {}
e.preventDefault();
});
}
.showcase {
width: 764px;
height: 875px;
margin: auto;
background-size: contain;
background-position: 50% 50%;
background-repeat: no-repeat;
-webkit-animation: blackjacket 6s infinite;
animation: blackjacket 6s infinite;
-webkit-animation-timing-function: steps(1, end);
animation-timing-function: steps(1, end);
}
@keyframes blackjacket {
/* black */
0% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/black%20jacket/front.webp')
}
33.3% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/black%20jacket/back.webp');
}
66.6% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/black%20jacket/side.webp');
}
100% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/black%20jacket/side.webp');
}
}
@keyframes whitejacket {
/* white */
0% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/white%20jacket/front.webp')
}
33.3% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/white%20jacket/back.webp');
}
66.6% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/white%20jacket/side.webp');
}
100% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/white%20jacket/side.webp');
}
}
@keyframes greyjacket {
/* grey */
0% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/grey%20jacket/front.webp')
}
33.3% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/grey%20jacket/back.webp');
}
66.6% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/grey%20jacket/side.webp');
}
100% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/grey%20jacket/side.webp');
}
}
@keyframes yellowjacket {
/* yellow*/
0% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/yellow%20jacket/front.webp')
}
33.3% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/yellow%20jacket/back.webp');
}
66.6% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/yellow%20jacket/side.webp');
}
100% {
background-image: url('https://connorlewis128.github.io/ShoppingPage/Dist/images/new%20product/yellow%20jacket/side.webp');
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<div class="colorchoice">
<h2>Choose Color</h2>
<div id="color">
<div class="btn-group2" role="group2" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="colorradio" id="black" autocomplete="off">
<label class="btn btn-secondary black" for="black"></label>
<input type="radio" class="btn-check" name="colorradio" id="white" autocomplete="off">
<label class="btn btn-secondary white" for="white"></label>
<input type="radio" class="btn-check" name="colorradio" id="grey" autocomplete="off">
<label class="btn btn-secondary grey" for="grey"></label>
<input type="radio" class="btn-check" name="colorradio" id="yellow" autocomplete="off">
<label class="btn btn-secondary yellow" for="yellow"></label>
</div>