Switch from animation to transition when hovering

I'm facing an issue with a link that has an infinite animation changing the background color. I'm looking to stop the animation and have it transition into a different background color upon hovering over it.

.startlink{
    background-color:#206a9e;
    color:#fff;
    border-radius:15px;
    font-family: 'Myriad Pro';
    -webkit-animation:changeColor 3.4s infinite;
    -webkit-transition:all 0.2s ease-in;
}

.startlink:hover{
    -webkit-animation-play-state: paused;
    background-color: #014a2a;
}

@-webkit-keyframes changeColor 
{
    0%   {background:#206a9e;}
    50%  {background:#012c4a;}
    100%   {background:#206a9e;}
}

Can anyone help me understand why this code isn't working as expected? Is there another method to achieve this without using Javascript?

Answer №1

Give -moz-animation: 0; a shot. Check out this demo. Using 0 sets the value of animation to default, effectively disabling any existing CSS3 animations.

Answer №2

-webkit-animation-play-state: paused as well as -webkit-animation-play-state: running

Answer №3

Discovered an alternative method to make this happen.

Create a new set of animation keyframes and trigger it on hover.

.startlink{
background-color:#206a9e;
color:#fff;
border-radius:15px;
font-family: 'Myriad Pro';
-webkit-animation:changeColor 3.4s infinite;
-webkit-transition:all 0.2s ease-in;
}

.startlink:hover{
-webkit-animation:hoverColor infinite;
}

@-webkit-keyframes changeColor 
{
0%   {background:#206a9e;}
50%  {background:#012c4a;}
100%   {background:#206a9e;}
}
@-webkit-keyframes hoverColor 
{
background: #014a2a;
}

Answer №4

After exploring various methods to achieve a desired functionality, I stumbled upon an unconventional solution using basic CSS techniques. You can check out the implementation in this interactive example. While not the most elegant approach, it successfully accomplishes the task at hand.

#menu, #yellow{
  position: fixed;
  top: 2.5vw;
  right: 2.5%;
  height: 25px;
  width: 25px;
  border-radius: 30px;
}

#menu{
  animation: blink 2s infinite;
transition: 1s;
}

@keyframes blink{
  0% { background-color: grey; }
  50% { background-color: black; }
  100% { background-color: grey; }
}

#yellow{
background-color: rgba(255, 0, 0, 0);
transition: 1s;
}

#disque:hover #yellow{
pointer-events: none;
background-color: rgba(255, 0, 0, 1);
}

#disque:hover #menu{
opacity: 0;
}
<div id="disque">
  <div id="menu"></div>
  <div id="yellow"></div>
</div>

Answer №5

Facing the same dilemma, I discovered a helpful solution.

To achieve this, create the desired animation and assign unique classes to each element involved.

Next, utilize jQuery's .mouseover() or .mouseenter() events to toggle between the assigned classes for each animation.

This method mirrors the handling of a burger menu, albeit with a different trigger mechanism.

Answer №6

Are you intrigued by the idea of creating a slideshow animation with a pause between two images?

var NumImg = 1; //Keep track of image number to display
var MaxImg = 3; //Total number of images in the directory (named 1.jpg, 2.jpg...)

function BackgroundAnimation() {
  NumImg = NumImg > MaxImg ? 1 : NumImg +=1;
  var MyImage = "http://example.com/Images/" + NumImg + ".jpg";
  $("#Img1").attr("src", MyImage);
  $("#Img2").fadeOut(3000, function() {
    $("#Img2").attr("src", MyImage);
    $("#Img2").fadeIn(1);
  });
}

setInterval("BackgroundAnimation()", 10000); //delay between changing images
#BackgroundAnim {
  position: fixed;
  height: 100%;
  width: 100%;
  margin: 0 0 0 -8;
}

#BackgroundAnim img {
  position: absolute;
  left: 0;
  height: 100%;
  width: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.2.3/jquery.min.js"></script>
<div id="BackgroundAnim">
  <img id="Img1" src="http://example.com/Images/1.jpg" />
  <img id="Img2" src="http://example.com/Images/1.jpg" />
</div>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Establish a minimum width requirement for a Bootstrap4 webpage and ensure that scrollbars are visible

As I work on designing a website, I am facing an issue with responsiveness that I am willing to accept for now. I am looking to establish a minimum width for the overall page to be around 1000px, with a horizontal scrollbar appearing if the screen width is ...

Struggling to align the footer of your webpage and ensure it adjusts proportionally with the window size?

After trying several codes that have worked before, I ran into a problem when attempting to place two div side by side for the footer. No matter what code I tried, I couldn't get it centered and responsive to the user window ratio. Even after consulti ...

What could be causing the last LI to drop onto a new line when floating UL to the right?

I'm currently working on creating a horizontal navigation that needs to align to the right side of the page. However, when I float the navigation to the right and then float all the list items to the left, the last item in the list breaks onto a new l ...

Ways to eliminate underline on list items with CSS

Currently, I am delving into frontend development with the NextJs framework. As a newcomer to this field, I am facing a challenge in creating a navbar that displays an underline below each menu item. Despite my attempts at using various CSS properties, non ...

Safari does not support font-face rendering, unlike Chrome

I am in the process of creating a typewriter-style font page using a local font. I have used @font-face to import it, and while it displays correctly on Google Chrome, it does not render properly in Safari. You can view the web page here: (you will need ...

Show the separation between columns in a bootstrap table

Can someone help me with setting up a cryptocurrency ticker display using Bootstrap? I want to add vertical lines between columns using border properties, but I'm not sure how to make the right side borders of the cells visible along rows. <!-- ...

Button displayed on complete Bootstrap 4.5 Card

When running the code below, the text "Click Me" appears when the mouse hovers over it. I actually want "Click Me" to be displayed for the entire card (list). <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" rel= ...

Instructions for transitioning a triangular shape from pointing downward to pointing upward utilizing CSS and jQuery

So, I'm working with this unique triangle shape represented in the image below: The CSS used to create it is as follows: .triangle { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; bo ...

Gallery not responsive on HTML/CSS site

Hi there, I'm a newcomer to Stack Overflow and currently diving into the world of HTML/CSS. I've hit a roadblock with my latest project - I'm trying to create a gallery of album covers, but when I try to 'zoom in' on the webpage (n ...

"Utilize CSS Flexbox to create a layout with set width and uniform

Within a container, I have organized three sections. As I adjust the size of my browser to a maximum width of 668px, I want section 1 and section 3 to be displayed in one row while section 2 is placed below them. The width of section 2 should be proportion ...

How can I use CSS to ensure that both cards and images are equal in size?

I am currently utilizing react, with Material-ui being used for the Cards. For the layout, I have implemented CSS Grid Layout for the Grid system. Presently, the structure looks like this: https://i.stack.imgur.com/0FDyY.png However, my desired outcome i ...

Getting rid of an accidental div around an input field that was generated by Bootstrap with the help of

I have been experimenting with creating a slider using Jquery and storing the input in an <input type="text" readonly>. Everything was working fine until I tried to place the input inside a popup-window div. This caused an extra div to be created aro ...

Is it possible to simultaneously execute an animate and a fade out effect?

Is there a way to simultaneously move "app1" to the left and fade it out? Currently, the functions are executing one after the other. I want them to occur simultaneously, without the left movement happening before the fade out. Thank you! <!DOCTYPE h ...

Upon clicking on a different div, a div will elegantly slide down from above the footer

I'm struggling with sliding a div from the bottom of the page. Here is my JSFIDDLE Currently, when I click on the blue box (arrow-hover), the div slides up (box-main). However, to hide the div (box-main) again, I have to click inside the box-main d ...

Modifying the Hover Color of the Navbar in Bootstrap 4: Tips and Tricks

Looking to customize the hover color of my navbar but struggling to find the right element in the inspect tool. Tried solutions from Stack Overflow with no luck, any suggestions would be appreciated! <!doctype html> <html lang="en> <hea ...

Using Bootstrap 3's hidden-xs class can help slim down the width of

I am currently testing out the Bootstrap 3 responsive grids and attempting to hide a column from a row when the screen size is small. However, I find that when the column disappears, the entire row seems to shrink in width. Here's the code causing me ...

Which specific CSS stylesheet do LinkedIn, Facebook, and Quora utilize for their websites?

I've been curious about how websites like Linkedin, Facebook, or Quora design their sites. When I view them in responsive mode in my browser, I noticed that the content stays fixed at 1000px or 1100px and doesn't change. However, when I access th ...

Using Google-Prettify with AngularJS

I have been attempting to implement Google Prettify in my AngularJS project. It seems to be functioning correctly on the main page, but once I navigate to another route using Angular (after ng-view), it stops working properly. You can check out the plunker ...

Adding design to distinct element after clicking a button

Struggling with a JS/Jquery issue on my portfolio website, I admit that I am still just an average programmer. My portfolio website has five buttons, each representing a different project. For each project, there is a corresponding text description and an ...

Dynamic motion for the circular progress bar during initialization

Seeking assistance to animate the round progress bar border upon page load. Looking for animations for various percentage values. Any suggestions are greatly appreciated! Thank you in advance! For a similar animation example, click here. .progress-circ ...