Is there a way to make a div come to life with animation when it's clicked, and then make it go back to its original

I've been dedicating several hours to finding a solution, but nothing has worked so far.

My goal is to set up an animation where the user clicks on a square image, causing it to 'flip' into a trapeze shape similar to the new Windows logo. At the same time, another div will slide out to the right from behind this element, displaying information related to the image.

While I have created a working example on my website, it currently only functions in webkit browsers due to the lack of vendor prefixes and the div behind not sliding out correctly yet. However, the concept is clear - something akin to the Windows 8 start screen tiles.

The animation I am using is flipInY from animate.css with the removal of the middle keyframes. Originally, I planned to use Hover to trigger the animation, but implementing this on a mobile site would be challenging. Therefore, I opted for a jQuery 'onClick' event as a better alternative.

Although I have successfully implemented the onClick switchClass JQuery function for the first animation, the second click merely restarts the animation rather than reversing it. I had the code here, but I removed it in search of a more effective solution that remains elusive.

This question and answer provide some insight into the issue, although it pertains to a different 'slideUp' animation and involves two separate buttons. I prefer to have a single button that toggles the effect.

Any assistance would be greatly appreciated, and if you believe I am approaching this task in the wrong manner, please feel free to suggest an alternate approach!

Answer №1

Have you experimented with this:

animation-direction:alternate;
-webkit-animation-direction:alternate; /* Works in Safari and Chrome */

These effects are really cool, by the way :)

Answer №2

In my opinion, the best choice would be to implement jQuery's toggleClass();

Answer №3

Do you think this could be a solution for your needs?

$('#rectangle').click(function() {
  $(this).toggle(
      function(){
        $(this).flippy({
            color_target: "#aa0621",
            direction: "right",
            duration: "750"
         });
      },
      function(){
        $(this).flippy({
            color_target: "#aa0621",
            direction: "left",
            duration: "750"
         });
      }
  );
});

Here is a demonstration of the code in action: http://jsfiddle.net/H6wA3/5/

Answer №4

Perhaps I may not be fully grasping your point, but take a look at this LIVE DEMO

Here is the HTML code:

<div class="wrap">
<div class="over">yellow</div>
<div class="box">red</div>
</div>

And the JavaScript code:

$('.over').click(function() {
$('.box').animate({marginLeft: '150',
                   width: '120',
                   height: '120',
                   marginTop: '-10'
                  }, 300);  


setTimeout( function(){
    $('.box').css('zIndex',80);
} , 400); 

$('.box').animate({marginLeft: '0'}, 300).animate({width: '100', height: '100', marginTop: '0'}, 300);
});

$('.box').click(function() {
$('.over').animate({
                    marginLeft: '150',
                    width: '120',
                    height: '120',
                    marginTop: '-10'
                    }, 300).css('zIndex',5); 

$('.box').css('zIndex',10);
setTimeout( function(){
    $('.over').css('zIndex',70);   
} , 400); 
$('.over').animate({
    marginLeft: '0'}, 300)
    .animate({width: '100',
          height: '100',
          marginTop: '0'}, 300);

});

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

<div class="firstHeaderClass"> What exactly is this?

Struggling to eliminate a recurring header across all my webpages for customization, I've hit a roadblock in identifying the source of this repeating header. Upon stumbling upon this code snippet in the header section, my efforts to decipher its ...

Executing a server-side Java function from client-side JavaScript or jQuery on a JSP page

My JSP file has a dropdown list where I can select different entity kinds. Upon selecting an entity kind, I want to populate another dropdown list with the field names associated with that entity kind. This requires calling a JavaScript function when chang ...

Troubleshooting problem with Angular ngx-bootstrap datepicker positioning on mobile devices

Having an issue with ngx-bootstrap/datepicker, it works fine on larger screens but not on mobile screens. Any assistance would be appreciated. https://i.sstatic.net/ZGdyQ.png When the screen size is reduced to mobile (even on actual mobile devices), it o ...

Can jQuery Autocomplete function without stopping at white spaces?

Is there a way to modify jQuery UI autocomplete so that it can handle multiple words instead of terminating with a space? For example, if you input "New York City", it should still filter results based on each word. $.ajax({ type: "GET" ...

Enhancing Alerts in Bootstrap 5.1+: Tweaking Text, Background, and Border Colors for Alert-Warning Messages using custom _variables.scss

Incorporating a custom _variables.scss file into my codebase is crucial for my project, and the way I import it is as follows: @import url('https://fonts.googleapis.com/css?family=Nunito'); @import 'variables'; @import 'bootstrap/s ...

Ajax causing submission of 'undefined' data

I have been utilizing an HTML form to send data to a Google sheet, and it was working perfectly fine. However, when I added Ajax code, the data being sent to the Google sheet always turned out to be "undefined". Removing the code resolved the issue, but it ...

Step-by-step guide on generating a fluid list with Express and HTML

Looking to create a dynamic list by fetching data from a JSON file. I want the list items to redirect me to specific content based on their IDs when clicked. However, my current approach is not working as expected, and the list needs to be truly dynamic. ...

Using jQuery.post to select and manipulate the target div displaying Google search results

I am trying to implement a custom form and display the results in a specific target DIV ('results') using ajax. However, I am facing difficulties and unable to figure out what is going wrong. Even after referring to this demo (https://api.jquery ...

"Troublesome issue with Bootstrap push and pull functionality not functioning correctly

I am currently experiencing issues with Bootstrap push and pull functionality. While the mobile view appears to be working correctly, the web view is shifted to the left. Any assistance on this matter would be greatly appreciated. Below is the code that i ...

What is the best way to reduce the size of an image taken from an image sprite rather than a standalone image?

I have an image sprite and I am looking to make a specific part of it appear smaller using CSS. Any recommendations or suggestions? Thank you in advance. ...

Issues are arising with the .mouseover functionality within this particular code snippet

Learning Javascript has been a challenge for me so far. I tried following a tutorial, but the result I got wasn't what I expected based on the video. I'm wondering why that is and how I can fix it. I'm aiming to make a box appear suddenly w ...

Tricks for disabling _blank behavior in jquery?

I'm currently integrating a widget into a webpage using PHP. The widget contains jQuery code that causes all links to open in an external page. Is there a way to override or disable this code so it doesn't impact every link on the page? My prefe ...

Repeating the execution of Asp.net MVC ajax once again

When using the Ajax.BeginForm method for form submission, I encounter an issue where multiple processes are initiated if the submit button is clicked quickly more than once. This results in the RefreshPosts(); script resetting the form elements. In the co ...

Interactive Communication: PHP and JQuery Messaging Platform

I am developing a social networking platform and I am looking to integrate a chat feature. Currently, I have a home.php page that displays a list of friends. The friends list is loaded dynamically using jQuery and PHP, like this: function LoadList() { ...

What methods can I employ to utilize a JSON response generated by PHP within jQuery?

Currently, I am in the process of creating a website and I'm working on gathering all the reviews stored in the database. Initially, my approach was to utilize PHP in the following manner: function get_all_reviews(){ $db = dbConnection(); $db ...

Customizing TableRow Hover Effects in React with Material-UI

I've been spinning in circles with this issue. It seems like I just can't grasp how class overrides function in Material-ui. I attempted to follow the advice in this response: CSS on Material UI components However, it didn't produce any res ...

Adaptive grids in Bootstrap

I've been using bootstrap and I'm trying to get the items to align next to each other, but using the bootstrap columns doesn't seem to be working for me. I may be coding it incorrectly. <link rel="stylesheet" href="https://cdn.jsdelivr ...

The importance of adding blank spaces in email formatting

A Visual Basic 6 application is sending a HTML email. The issue is that when the email is received, all blank spaces are removed. For example, in the code snippet below, the email sent says "this is a test" instead of displaying the actual spaces on line ...

Using jQuery.dataTables to choose all rows except the final column

I'm utilizing a table with jQuery.dataTables. I have a requirement to input dates in the last column. However, when I click to input a date, the row becomes deselected. The following code is meant for selecting all rows: Displayed below is the DataT ...

Utilizing jQuery functions within Vue components in Quasar Framework

I've recently started delving into web app development and I'm encountering some basic questions regarding jQuery and Vue that I can't seem to find answers to. I have an application built using the Quasar Framework which frequently involves ...