Creating a larger spinning div using CSS3 animation

I am looking to add a fun hover effect to my div where it spins and zooms in at the same time.

Here is what I have so far:

[html]

    div class="myMsg">>
        <p id="welly" style="color: #009">Welcome to Y3!<br><br><br>Thanks for stopping by!</p>
</div>

[css]

.myMsg {
    background: white;
    width: 800px;
    height: 500px;
    margin: 100px auto;
    border: 1px solid black;
    opacity: 0.5;
    -webkit-transform: rotate(360deg) scale(.1,.1) skew(45deg) translateX(-300px);
    box-shadow: 0px 0px 200px grey;
}

.myMsg:hover {
    opacity: 1;
    -webkit-transform: rotate(360deg) scale(1, 1) skew(0deg);
    box-shadow: 0px 0px 200px grey;
}

I want the spinning animation to happen before it scales back to its regular size.

Any assistance would be greatly appreciated!

Answer №1

Firstly, let's demonstrate that this task is achievable.

Now that we've established that, let's delve into the details and show you how to accomplish it.

Begin by utilizing animation to create animated effects and achieve the desired rotation effect. Simply using a transition won't suffice because transitioning between 0 and 360 doesn't result in any visible change. Therefore, animate your properties from one value to another upon hover. Your code snippet will resemble the following:

@keyframes spin {
    from { transform: scale(.1,.1) skew(0deg) rotate(0deg); }
    to { transform: scale(1,1) skew(0deg) rotate(360deg); }
}
.myMsg:hover {
    animation: spin 1s forwards;
}

The @keyframes declaration specifies the animation sequence, defining the transformation from initial properties to final ones. Subsequently, assign your :hover pseudo-class to trigger the specified animation. The essential properties for the animation include animation-name, animation-duration, and animation-fill-mode (indicating that it should retain the final state properties when the animation concludes). Don't forget about Webkit prefixes for compatibility.

Furthermore, I applied a transition: transform 1s; on the .myMsg class to ensure smooth animation upon mouse exit. Nevertheless, note that Webkit might exhibit slight inconsistency and choppiness due to interaction nuances between the two animations. It's worth acknowledging that with experimental features like this, results may vary.

A couple of additional points to consider:

  • Your CSS requires refinement for cross-browser compatibility
  • You're initially defining one transform property and then promptly overriding it. All transforms must be grouped within the same declaration – they cannot be separated as observed

Answer №2

Provide instructions for creating a never-ending CSS animation using keyframes to make an element spin, and then activating it upon hover. Utilize transitions to modify the size (height/width) properties when hovering in CSS as well.

For reference, check out this example: http://jsfiddle.net/6guCd/

div {
    margin: 100px;
    width: 100px;
    height: 100px;
    background: #f00;
    -webkit-transition: all 200ms ease;
    -moz-transition: all 200ms ease;
    -ms-transition: all 200ms ease;
    transition: all 200ms ease;
}
div:hover {
    margin: 50px;
    width: 200px;
    height: 200px;
    -webkit-animation-name: spin;
    -webkit-animation-duration: 4000ms;
    -webkit-animation-iteration-count: infinite;
    -webkit-animation-timing-function: linear;
    -moz-animation-name: spin;
    -moz-animation-duration: 4000ms;
    -moz-animation-iteration-count: infinite;
    -moz-animation-timing-function: linear;
    -ms-animation-name: spin;
    -ms-animation-duration: 4000ms;
    -ms-animation-iteration-count: infinite;
    -ms-animation-timing-function: linear;

    animation-name: spin;
    animation-duration: 4000ms;
    animation-iteration-count: infinite;
    animation-timing-function: linear;
}
@-ms-keyframes spin {
    from { -ms-transform: rotate(0deg); }
    to { -ms-transform: rotate(360deg); }
}
@-moz-keyframes spin {
    from { -moz-transform: rotate(0deg); }
    to { -moz-transform: rotate(360deg); }
}
@-webkit-keyframes spin {
    from { -webkit-transform: rotate(0deg); }
    to { -webkit-transform: rotate(360deg); }
}
@keyframes spin {
    from {
        transform:rotate(0deg);
    }
    to {
        transform:rotate(360deg);
    }
}

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

Slide the menu off to the right

Check out these images to see my progress: Main Image. When you click on the menu, everything shifts right. I've managed to set up the push menu, toggle switch menu, and main divs. Now I need help with centering the 3 lines that are clicked within th ...

When utilizing the HTML select element, the <option> tag may only display the initial letter of the chosen option

Here is a snippet of my PHP code: <?php if($_POST['post'] == 'Post') { $cat = $_POST['cat']; $update = "UPDATE table SET category='$cat' WHERE id = '$id' "; $result = mys ...

What's the best way to make two buttons appear side by side on a webpage?

I need to have my two buttons, Update and Cancel, displayed next to each other on the same line. Currently, there is a gap between the two buttons as shown in the attached image. Below is the HTML code I am using: <div class="form_block span2"> ...

How to display percentage value on ReactJS Material UI progress bar

For displaying the progress completed in numbers, I utilize the Linear Determinate component. Take a look at the image below to see how it appears. ...

Creating a full-height application with CSS3 Flexbox and managing overflow

I'm currently working on an app that utilizes a traditional email layout similar to the one illustrated below. Using the new CSS3 flexbox model, everything was functioning perfectly until I added the feature for users to dynamically insert new items ...

Is it possible to change the color of specific days of the week (like Mondays, Tuesdays, etc.) in JQueryUI's datepicker?

Is it possible to customize the appearance of specific weekdays (such as all Mondays, all Tuesdays for the entire year) in the JQueryUI datepicker by changing their color? While there are existing methods to select certain dates and disable holidays, I h ...

HTML file unable to connect with CSS stylesheet

I'm facing an issue where my CSS stylesheet and HTML files aren't linking properly. Here is the code snippet from my HTML file: <head> <title>Website Sample</title> <meta charset="UTF-8"> <meta http-equiv= ...

Step-by-step guide on achieving 100% height for the <main> element in a Material UI drawer demo

I have a question regarding the Material UI drawer. In my project, I am trying to change the background color of the main tag. However, the main tag's height is restricted to the content inside. Check out this link for reference Setting the height t ...

File bootstrap.min.css is currently experiencing compatibility issues

I am currently working on a website where I have two images that are displaying vertically. However, I would like these images to be displayed horizontally with animation. I attempted to use Bootstrap to achieve this horizontal layout, but when I include ...

Adding a border around the `<tr>` elements in a table

How can I add a border to the <tr> element (t_border), without the inner table inheriting the style from the outer one? <table> <tr> <td>A</td> </tr> <tr> <td> <ta ...

Ways to modify the hue of an li element in the context menu upon hovering

I'm currently working on a project that involves VueJS and Bootstrap. To enhance user experience, I've incorporated a context menu using the npm package called vue-context Vue Context Menu When a user hovers over an item on the context menu, the ...

Is there a way to adjust only the height of a responsive image?

Increasing the Height of an Image on a Mobile Device! I have an image that displays as the header of my website. When I resize the window to mobile format, the image resizes too. However, I want the height of the header image to be longer! Is this possibl ...

Tips for addressing the issue of button flickering due to CSS transitions

Is there a solution to prevent flickering without compromising the intended design? The issue arises when hovering over a moving or animated element and accidentally un-hovering because it moves beneath the cursor. <!DOCTYPE html> <html> &l ...

Unveiling the Mystery: How Browser Thwarts Server Push in HTTP/2.0

After studying the documentation of HTTP/2.0, I discovered that it is feasible to completely close a referenced stream using the RST_STREAM frame. Check it out here: ()! I am curious about how this feature can be implemented in popular web browsers such a ...

The issue of jumpy CSS background on full screen mode for mobile devices is causing

While developing a web app, I encountered an issue with the responsive (parallax) full screen background. On mobile devices, the background does not extend below the toolbar, causing a jumpy effect when scrolling up and down in Firefox. I have tried differ ...

Stop capturing mouse and keyboard events within a specific div element on all web browsers

I manage a website with forms that have jquery autosave features and are updated using ajax. These forms include various types of input elements such as textboxes, jQuery UI datepickers, and time pickers... <div id="content"> <form id="line1"&g ...

Issue: Trouble with Rotating Tooltips in Javascript

I am facing a challenge with the tooltips on my website. I want to ensure that all tooltips have a consistent look and transition effects, but I am struggling to achieve this. The rotation and other effects applied using javascript are not functioning prop ...

Tips for rearranging sibling divs while maintaining the order of their child elements

Is there a way to shuffle the order of div classes shuffledv, while maintaining the same order of id's each time the page is refreshed? <div class="shuffledv"> <div id="2"></div> <div id="3"></div> <div id="1">< ...

Having trouble getting your React project to work because NPM start won't cooperate? Here are some troubleshooting tips

Hello, I recently downloaded a React project from https://github.com/fabiau/jc-calendar. However, when I try to run npm start, I encounter error messages. I have attempted to use "NPM Fund" and "NPM Update", but unfortunately, neither of them resolved the ...