Learn the steps to animate a div by clicking on another div, and explore how to make the animated div interact with and move other elements

I am trying to figure out how to animate a div when I click on another div. I want the animated div to not only move, but also push other elements around it instead of just covering them up. Currently, my div animates on top of images below it, but I want it to interact with and push those images. Any suggestions on how to achieve this would be greatly appreciated.

Here is the link to my fiddle: Fiddle Link

In my fiddle, there is an image of a horse. How can I make the animated div push this image down as it animates?

Another challenge I am facing is triggering the animation of the green div when clicking on the blue div below it. I have tried different methods without success so far. Any tips or guidance on how to accomplish this would be helpful.

HTML

<div class="Invisible"> </div>
<img src="http://lorempixel.com/output/animals-q-c-1244-480-10.jpg" class="this"/>
<div class="thing"></div>

CSS

.Invisible {
    z-index:2;
    position:absolute;
    top:0;
    left:0%;
    background-color:green;
    height:20%;
    width:100%;
}

.Invisible:hover {
    z-index:2;
    position:absolute;
    top:0;
    left:0;
    background-color:green;
    height:20%;
    width:100%;
    -webkit-animation: Rooms 1s; /* Chrome, Safari, Opera */ 
    animation: Rooms 1s;
}
@-webkit-keyframes Rooms {
    from {height:20%; }
    to {height:60%; }
}

@keyframes Rooms {
    from {height:20%; }
    to {height:60%;}
}

.this {
    position:absolute;
    top:20%;
    left:0;
    width:100%;
    height:50%;
}
.thing {
    background-color:blue;
    position:absolute;
    top:80%;
    left:20px;
    height:20px;
    width:20px;
}

Answer №1

In this scenario, using @keyframes is not necessary. You can achieve the desired effect with a simple CSS transition.

Furthermore, the div appears to be overlaying due to its position being explicitly set to absolute. Refer to this Fiddler for clarification.

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

I recently discovered how to modify the video source (src) within an html5 source tag, but I am encountering varied outcomes when using it within a function or with inline javascript

When attempting to change the src of a video tag using Javascript, I encountered an issue. The code works fine when placed inline, but as soon as I try to include it within a function or in the "onclick" event of a button tag, nothing happens. There are no ...

Spinning an object using JQuery

I am currently working on a project to test my skills. I have set up a menu and now I want to customize it by rotating the icon consisting of three vertical lines by 90 degrees every time a user clicks on it. This icon is only visible on smartphones when t ...

Is there a way to retrieve the original value of the substr value?

I successfully retrieved the correct value using the substr() method, but I am facing difficulty in getting back the original value. Can someone please guide me on how to achieve this? For example: "AAAAAA" -> AA... but I am unable to revert from AA.. ...

Preventing the negative consequences of being colorblind through programming techniques

My experience as a web developer has taught me that poor color contrast on a website can severely impact revenue. I am determined to change this, but have encountered an issue. On my site, there is a section where users can select a color and see it displa ...

Dynamic Data Binding in Ionic 2

One challenge I am facing is with creating my own info window for a Google Maps marker. Whenever I click on the marker, a div is displayed but the information inside the div does not get updated. It seems like the event.title remains unchanged from its old ...

Submitting an HTML form to trigger a PHP function through AJAX

I am currently working on a task that involves POSTing an email address entered in an HTML form to a PHP script for storage in a database. The script should also handle error messages if the user inputs an invalid email address. I want to make this process ...

Ways to prevent websites from switching to landscape mode

Is there a way to prevent landscape mode on my website and restrict users to portrait mode, especially for devices with screen widths below 777px? I have custom headers that take up fixed position space of around 100px on the screen. If it is possible to ...

How can I remove the arrow from a CSS selector?

I'm looking to enhance the appearance of a select element on my webpage, so I've crafted some custom CSS: .selectWebDropDown { background-color:Transparent; background: url(../Images/ddl_Normal.png) no-repeat right #FFFFFF !important; ...

Angular offers a simple solution for adding events to all "p", "span", and "h1" elements easily

I am attempting to implement a "double click" event on all text HTML elements (p, span, h1, h2, etc.) across all pages in order to open a popup. I believe there should be a more efficient way than adding (dblclick)="function()" to each individual element. ...

A surprise awaits in IE with the unusual appearance of a div display

body { background: #9cdcf9 url(/images/left_cloud.png) bottom left no-repeat; font-family:\"Trebuchet MS\"; padding:0; margin:0; border:0; } #cloud-container { width: 100%; background: url(/images/right_cloud.png) bott ...

CSS Navigation Bar Fails to Function Properly on Mobile Devices

Check out the plunkr I have created by visiting: http://plnkr.co/edit/gqtFoQ4x2ONnn1BfRmI9?p=preview The menu on this plunkr functions correctly on a desktop or laptop, but it doesn't display properly on a mobile device. I suspect that the issue may ...

The content in an app using Ionic and Angular is being obstructed by the bottom tabs, preventing users

I am facing an issue with my Ionic and Angular app. When I place tabs at the bottom of my page, outside the ion-content, the scrolling stops working inside the ion-content and the fab button, which is located inside the ion-content, ends up covering the ta ...

Designing a dropdown menu using CSS

Currently, I am facing a requirement to create a menu that should resemble the image provided below. In the past, I have experience working on simple drop-down menus, but this time the specifications are a bit unique. The top menu links should change colo ...

Mobile-friendly persistent navigation located beneath the header, inspired by the iOS7 browser design

This issue is really causing me a headache and slowing down progress on my project because I can't seem to figure it out. Currently, I am working on designing a mobile-friendly website and conducting tests in iOS7/OSX. The layout I am aiming for inc ...

Tips for including a class in a HTML document using jQuery?

I have successfully included my header and footer in separate HTML files using jQuery's .load() function. The jQuery code I used is shown below: $(function(){ $("#header").load("page-component/header.html"); $("#footer").load("page-component/f ...

Applying right margin to the nav bar without causing issues with the navbar collapse in Bootstrap - how to do it?

Objective: The goal is to adjust the position of the navigation bar items using padding or margin as indicated in red: https://i.sstatic.net/5vYTc.png Issue I noticed that applying a right padding or margin affects the collapsed (on mobile screen) list ...

If the initial hidden field contains data, then assign the checkbox value to a different hidden input field

I am dealing with a group of 4 checkboxes. Once any two checkboxes have been checked, their values are duplicated into two hidden input fields. The value of the first checked checkbox is copied to the first input with id="checkedBox1" Now, I am trying t ...

Utilizing a Bootstrap column design with two columns in place - one column set at a fixed width while the second column stretches across the remaining

Need help with adjusting two columns on a webpage? The right column is fixed at 300px width, while the left column should take up the remaining space. Using flex works well, but when adding a responsive ad to the left column, it extends beyond the availabl ...

Save the ID values for dialogs that are created dynamically in the store

Encountering an issue with storing values in dynamically created buttons that can open a dialog box. The dialog is the same for all buttons, so the definition looks like this: $('<div id="dialog-form" title="Change coordinates">' + ...

Creating a personalized image resizing function for WordPress

I have implemented the following code in functions.php to fetch the first image from WordPress posts: function grab_first_image() { global $post, $posts; $first_img = ''; ob_start(); ob_end_clean(); $output = preg_match_all('/< ...