Hi folks,
I have a question in regards to reworking a function: I have two Code Pen links:
At the first link (1), I created two lights, one red and one green. The green light glows as long as the animated slideshow is running, and when a user hovers over on the slides of the slideshow the green light is turned off and a red light glows instead. Also when a user hovers over the content of the âPortfolioâ dropdown menu bar, the red light rapidly blinks.
However, in the second Code Pen link (2), I added a function to make the green light blink instead. However, as a result of adding this new function, now when the user hovers over one of the slides of the slideshow, the red light no longer glows. And also, when the user hovers over the content of the âPortfolioâ dropdown menu bar, the red light no longer blinks. Can you help me fix this?
Here is my old code:
//part 1: add green light to "Portfolio" menu bar button that operates based on status of animation (glows green) And turn of green light and make red light glow when
mouseover` slideshow
//part 2: make red light blink while mouse is over contents of âPortfolioâ button drop-down menu
/part 1/
var showcase = document.querySelector(âfigureâ);
showcase.addEventListener(âmouseoverâ, function(){
$(".red").addClass(âglow-redâ);
$(".green").removeClass(âglow-greenâ); });
showcase.addEventListener(âmouseoutâ, function(){
$(".red").removeClass(âglow-redâ);
$(".green").addClass(âglow-greenâ);
});
/part 2/
var dropdown = document.querySelector(â.dropdown-contentâ);
dropdown.addEventListener(âmouseenterâ, blinking);
dropdown.addEventListener(âmouseleaveâ, stopBlinking);
let isBlinking = false;
var element = $(".red");
function blinking() {
if (!isBlinking) {
isBlinking = true;
var shown = true;
var element = $(".red").addClass(âglow-redâ);
interval = setInterval(toggle, 100);
function toggle() {
if (shown) {
element.hide();
shown = false;
} else {
element.show();
shown = true;
}
}
}
}
function stopBlinking() {
var element = $(".red").removeClass(âglow-redâ);
clearInterval(interval)
isBlinking = false;
element.show()
}
`
New addition to code:
`
//make green light blink (while slideshow is running)
var element = $(".glow-green");
var shown = false;
setInterval(toggle, 450);
if(hidden) {
element.show();
shown = true;
} else {
element.hide();
shown = false;
}
`