Skip to content Skip to sidebar Skip to footer

How To Animate Css Animated Hamburger Icon On Mouseover

I've got an animated CSS Hamburger icon at http://elijahmanor.com/css-animated-hamburger-icon/ and I wanna need to use it but I want to use it via hover to view set ex(x) and whe

Solution 1:

You can do it using mouseover function.

document.querySelector("#nav-toggle")
  .addEventListener("mouseover", function() {
    this.classList.toggle("active");
  });
#nav-toggle {
  position: absolute;
  left: 50%;
  top: 50%;
}

#nav-toggle {
  cursor: pointer;
  padding: 10px35px16px0px;
}

#nav-togglespan,
#nav-togglespan:before,
#nav-togglespan:after {
  cursor: pointer;
  border-radius: 1px;
  height: 5px;
  width: 35px;
  background: black;
  position: absolute;
  display: block;
  content: '';
}

#nav-togglespan:before {
  top: -10px;
}

#nav-togglespan:after {
  bottom: -10px;
}

#nav-togglespan,
#nav-togglespan:before,
#nav-togglespan:after {
  transition: all 500ms ease-in-out;
}

#nav-toggle.activespan {
  background-color: transparent;
}

#nav-toggle.activespan:before,
#nav-toggle.activespan:after {
  top: 0;
}

#nav-toggle.activespan:before {
  transform: rotate(45deg);
}

#nav-toggle.activespan:after {
  transform: rotate(-45deg);
}
<aid="nav-toggle"href="#"><span></span></a>

Solution 2:

You just need to use mouseover instead of hover at your script.

document.querySelector("#nav-toggle")
  .addEventListener("mouseover", function() {
    this.classList.toggle("active");
  });

Solution 3:

The hover event is called mouseover.

The events name are the classic HTML DOM Events, just without the on prefix. For example, use mouseover instead of onmouseover.

document.querySelector( "#nav-toggle" )
  .addEventListener( "mouseover", function() {
    this.classList.toggle( "active" );
  });
#nav-toggle { position: absolute; left: 50%; top: 50%; }

#nav-toggle { cursor: pointer; padding: 10px35px16px0px; }
#nav-togglespan, #nav-togglespan:before, #nav-togglespan:after {
  cursor: pointer;
  border-radius: 1px;
  height: 5px;
  width: 35px;
  background: black;
  position: absolute;
  display: block;
  content: '';
}
#nav-togglespan:before {
  top: -10px; 
}
#nav-togglespan:after {
  bottom: -10px;
}

#nav-togglespan, #nav-togglespan:before, #nav-togglespan:after {
  transition: all 500ms ease-in-out;
}
#nav-toggle.activespan {
  background-color: transparent;
}
#nav-toggle.activespan:before, #nav-toggle.activespan:after {
  top: 0;
}
#nav-toggle.activespan:before {
  transform: rotate(45deg);
}
#nav-toggle.activespan:after {
  transform: rotate(-45deg);
}
<aid="nav-toggle"href="#"><span></span></a>

Solution 4:

You need to use mouseover event.

document.querySelector( "#nav-toggle" )
  .addEventListener( "mouseover", function() {
    this.classList.toggle( "active" );
  });
#nav-toggle { position: absolute; left: 50%; top: 50%; }

#nav-toggle { cursor: pointer; padding: 10px35px16px0px; }
#nav-togglespan, #nav-togglespan:before, #nav-togglespan:after {
  cursor: pointer;
  border-radius: 1px;
  height: 5px;
  width: 35px;
  background: black;
  position: absolute;
  display: block;
  content: '';
}
#nav-togglespan:before {
  top: -10px; 
}
#nav-togglespan:after {
  bottom: -10px;
}

#nav-togglespan, #nav-togglespan:before, #nav-togglespan:after {
  transition: all 500ms ease-in-out;
}
#nav-toggle.activespan {
  background-color: transparent;
}
#nav-toggle.activespan:before, #nav-toggle.activespan:after {
  top: 0;
}
#nav-toggle.activespan:before {
  transform: rotate(45deg);
}
#nav-toggle.activespan:after {
  transform: rotate(-45deg);
}
<aid="nav-toggle"href="#"><span></span></a>

Post a Comment for "How To Animate Css Animated Hamburger Icon On Mouseover"