:hover does not activate the animation forwards

Why won't the animation: forwards work on :hover? The animation itself is functioning properly, but the command "forwards" isn't.

The Issue:

Here's the HTML code snippet:

<img src="images/notebook_desk.svg" class="notebook-cover">

Here's the CSS code snippet:

.notebook-cover{
max-width: 100%;
width: 100%;
height: auto;
display: block;
grid-column: 4;
margin-left: -40px;
transform-style: preserve-3d;
transform-origin: 0 50%;
transform: perspective(2000px);
z-index: 2;
}
.notebook-cover:hover{
    animation: CoverBook 2s forwards
}
@keyframes CoverBook{    
    to{
        transform: rotateY(180deg);
        z-index: 4;
    }
}

Answer №1

It's not entirely clear what your goal is, but if you want the cover to maintain its position even when it's no longer in the :hover state, you could utilize the animation-play-state property.

.notebook-cover {
  max-width: 100%;
  width: 100%;
  height: auto;
  display: block;
  grid-column: 4;
  margin-left: -40px;
  transform-style: preserve-3d;
  transform-origin: 0 50%;
  transform: perspective(2000px);
  z-index: 2;
  background: red;
  width: 500px;
  height: 500px;
  animation: CoverBook 2s forwards paused;
}

.notebook-cover:hover {
  animation-play-state: running;
}

@keyframes CoverBook {
  to {
    transform: rotateY(180deg);
    z-index: 4;
  }
}
<div class="notebook-cover"></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

Interactive image rotator featuring navigation buttons for next and previous slides

I recently followed a tutorial from W3Schools Now, I am looking to enhance it by adding previous / next buttons for the indicators, rather than for the slider itself Here is what I aim to accomplish: https://i.sstatic.net/qH1PQ.png Below is the code sn ...

The animatedModal.js dialog box is causing the link to be unclickable, despite having a z-index of -9999

I am currently utilizing animatedModal.js for creating simple dialog boxes on my website. Everything is functioning perfectly, except for one issue - I am unable to click on the link to my logo at the top of the page because the modal with opacity:0; z-ind ...

Navigate to the left smoothly while maintaining an inline display and automatically adjusting height, with rows functioning correctly but columns

My layout consists of a grid with 8 boxes containing images. Each row has 4 columns, and there are 2 rows in total. The boxes are set to float: left and display: inline. Everything aligns perfectly when the height is fixed. Here is an example: Example Ima ...

Modifying the background hue of a text box within an external stylesheet

I'm currently facing an issue where I need to change the color of a textarea when a radio button is clicked. There are 4 radio buttons, so the textarea should change color 4 times for each button. I am working in reactjs and despite researching the pr ...

identifying the element targeted on dynamically created links with the help of jquery

I have created dynamic links where clicking on a country link displays the cities of that particular country. I am trying to retrieve the event.target.id of the dynamically generated city link when it is clicked. $(".countryName").children().on('cl ...

Menu collapse alignment upon hovering

I've spent over an hour grappling with this problem and can't seem to find a solution. Whenever the navigation menu collapses and I hover my mouse over the SHOP item, it shifts the SHOP element to the left. When I move the cursor away, it return ...

How can we automatically add dividers after a certain number of elements in CSS?

Is there a way to create a responsive layout with CSS that automatically adds a divider after a certain number of elements? For example, I have a set of elements with the class .beers, and I want to insert a .divider element after every 5th .beers element ...

What is the correct way to target CSS child elements?

If I wanted to customize the background of the initial 2 <div> elements within the "main" <div> in the following HTML snippet. SOURCE CODE <div class="main"> <div>1</div> <div>2</div> <div>3< ...

Animate.css: activate animations upon entering the viewport during scrolling

I'm currently testing out animate.css for my project. Here's a snippet of my code: <h2 class="lazyload animate__animated animate__rotateInDownLeft" data-link="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min ...

Error in Javascript: Null Object

I have created an upload page with a PHP script for AJAX, but I'm encountering errors in Firebug. Also, the upload percentage is not being returned properly. Currently, I can only do one upload in Firefox and the script doesn't work in Chrome. H ...

Tips for effectively interpreting a json string

Trying to extract specific fields from a JSON string and display them on an HTML page, but encountering the following error: SyntaxError: JSON.parse: unexpected character at line 1 column 2 of the JSON data This is the JSON being sent: { "Order0& ...

The options in the drop-down menu appear to be stuck and remain in place

Can someone with expertise lend me a hand? I've been racking my brain over this issue, and while I feel like I'm on the right track, I just can't seem to make my sub-sub menu items drop down to the right on hover. I suspect there might be c ...

Having trouble with implementing Jquery for inserting an element and then animating it using CSS through a class change

I am trying to insert an element using the "insertAfter" method and then add a class to trigger a CSS animation. It seems to work when I use a timeout function: First Approach (with Timeout) $content.insertAfter($("#2")); setTimeout(function(){ $con ...

Firefox with Ajax bug bar

I have encountered an issue with my Navbar specifically on Firefox. The problem I am facing is that the Navbar is flickering, constantly growing and shrinking. Interestingly, this issue does not appear when using Chrome or Opera. I'm curious to know ...

The data being transmitted by the server is not being received accurately

Hey there! I've recently started using express.js and nodejs, but I've encountered an issue where my server is sending me markup without the CSS and JS files included. const express = require('express'); const app = express(); const htt ...

Preventing the window from resizing while an AJAX query is in progress

I have a script in jQuery that serves as a search tool and also has the capability to resize an element to match the screen height minus 40 pixels whenever the window is resized. However, I am looking for a way to turn off the resizing feature when a searc ...

Trouble displaying AngularJS $scope.data in the HTML code

I'm experiencing an issue where the data received from a POST request is being logged in the console, but is not displaying on the HTML page. Despite having a controller set up, the {{user}} variable is not appearing on the HTML page. While I can se ...

My header has a video background that appears aesthetically pleasing on a desktop screen. However, when viewed on a mobile device, it is off-center and doesn't span the full

I am having an issue with a header that has a video background. It looks great on desktop, but on mobile devices, it is only taking up about 2/3 of the screen width and is aligned to the left side instead of filling the entire width. I have tried several ...

Implement a collapsible navbar using bootstrap

To create a responsive navbar that collapses into a burger menu when clicked, you can use the following HTML structure: <body> <header id="nav-wrapper"> <img id="logo" src="images/event-logo.png" /> <nav class="n ...

Component template using Knockout.js and RequireJS for HTML widgets

Trying to implement the widget example for knockout from here. Unfortunately, I am having issues loading the template from an external HTML file using requirejs. ko.components.register('like-or-dislike', { template: { require: &apos ...