Is it possible to make a div jump or bounce if it has a flex display?

I'm looking to add some interactive animation to an image inside a div when my mouse hovers over it.

To better explain the issue I'm facing, I created a quick representation of what I want to achieve in the code below.

My goal is to have the text bounce slightly every time the mouse is moved over the image or text within the container.

The challenge I encountered is that elements do not seem to bounce when they are part of a flexbox layout. However, I haven't been able to find any conclusive evidence in the documentation to support this theory.

Could someone provide guidance on how to implement the bouncing effect while utilizing flexbox?

$(document).ready(function() {
        $('.text').hover(function() {
          $(this).toggle("bounce",{times: 3}, "slow");
        });
      });
.one{
        margin:0;
      }

      .container{
        height:500px;
        width:500px;
        background-color:gray;
        display:flex;
        flex-wrap:wrap;
        align-items:horizontally;
        justify-content:space-around;
        align-items:center;
      }
      .dog{
        background-color:red;
        height:100px;
        width:100px;
      }
      .cat{
        background-color:blue;
        height:100px;
        width:100px;
      }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <!DOCTYPE html>
      <html>
        <head>
        </head>
      <body>
        <div class="one">
          <div class="container">
            <div class="dog">
              <div class="text">Hello Dog</div>
            </div>
            <div class="cat">
              Hello Cat
            </div>
          </div>
        </body>

Answer №1

After including the jquery-ui scripts/css, everything worked perfectly:

The bounce effect that was utilized is a feature of the jQuery UI library - you can find more information about it here.

A demonstration can be seen below:

$(document).ready(function() {
  $('.text').hover(function() {
    $(this).toggle("bounce", {
      times: 3
    }, "slow");
  });
});
.one {
  margin: 0;
}
.container {
  height: 500px;
  width: 500px;
  background-color: gray;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-around;
  align-items: center;
}
.dog {
  background-color: red;
  height: 100px;
  width: 100px;
}
.cat {
  background-color: blue;
  height: 100px;
  width: 100px;
}
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/smoothness/jquery-ui.css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<!DOCTYPE html>
<html>

<head>
</head>

<body>
  <div class="one">
    <div class="container">
      <div class="dog">
        <div class="text">Hello Dog</div>
      </div>
      <div class="cat">
        Hello Cat
      </div>
    </div>
</body>

Answer №2

Download the CSS file from the website I've given you and include it in the head section of your code. Make sure to utilize the specified keywords on any text, buttons, or images for it to function correctly. You can find the link here.

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

Can the functions passed into Material-UI withStyles() be relocated within the component?

Attempting to break down the components of my dashboard into smaller parts has proven challenging due to their dependence on drawerWidth. Initially, I considered moving drawerWidth into the state so it can be passed down to each component. However, I encou ...

The useCallback hooks persist outdated values when the list is refreshed

Why am I not getting the expected values every time the function onRefresh is called using Hooks? Example when onRefresh is called twice: Expected values: true 0 20 false true 0 20 false Received values: false 0 0 false false 20 20 false Initial st ...

Add a class individually for each element when the mouse enters the event

How can I apply the (.fill) class to each child element when hovering over them individually? I tried writing this code in TypeScript and added a mouseenter event, but upon opening the file, the .fill class is already applied to all elements. Why is this ...

Is there inconsistency in the behavior of json.parse when given the same input?

This query pertains to the differentiation in outputs resulting from various inputs I am not seeking guidance on achieving a specific output. The reason behind the discrepancy in output between two scenarios, despite using the same argument for the JS ...

Automatically clear out table rows once the maximum row limit is reached, then append new data using the WebSocket data in JavaScript

Recently, I delved into JavaScript and faced a dilemma with my Bitcoin Price update dashboard. The data is streaming in through an external WebSocket, updating the prices every second. But here's the catch - the table rows are going crazy! To maintain ...

Express.js code is experiencing difficulties with autocomplete functionalities

jQuery autocomplete code example [Express JS code for retrieving data][2\ Example of fetching data in Express JS ...

integrating the WordPress header into the WHMCS client portal

While working on a project, I am facing the challenge of aligning the WHMCS client area with my WordPress site. Progress has been made, but I have hit a roadblock. My goal is to integrate the header of my WordPress site into WHMCS. I initially attempted t ...

Maximizing the efficiency of critical rendering path while utilizing bootstrap

Is it feasible to enhance the critical rendering path (like Google and Facebook) while utilizing Bootstrap 3? Facebook opted for inlining styles connected to the header and sidebars. Meanwhile, Google inlined all styles since they have minimal styles for ...

Trigger an Ajax request upon user confirmation, which will only be prompted based on the result of a previous Ajax call

Currently, I am facing a challenging issue surrounding asynchronous calls: A specific JQuery function is triggered on user click. This function then requests a PHP file to check if the user input overlaps with existing information in the database. If an o ...

Using the information selected from the dropdown menu, the table was refined through an AJAX request

Having a small issue with ajax when working on my project. I have two actions in the view: <body> @Html.Action("SetSearchFilter") @Html.Action("FillTable") </body> The first action is a DropDownList: @Html.LabelFor(m => m.Manager, ...

Struggling with the development of a crossfading image gallery using jQuery's .animate() function while ensuring compatibility with IE8

Seeking assistance in creating a crossfading image gallery using jQuery and the .animate() function. I'm struggling to solve the issue of smooth fadeIn for the next image while maintaining compatibility with IE8. https://jsfiddle.net/Vimpil/fqhc1e9m/ ...

Struggling to start the node express server running

I'm trying to set up a node server using express to run nodemailer. My frontend is built with create-react-app - I believe there should be no issues in that area. I have a few questions: Why isn't my express server functioning properly? Why do I ...

Unable to retrieve JSON data from a PHP file hosted on the server

I have a server-side database with a table called "customers" and a column named "names". My goal is to send a request to the server asking for the first two records in the "customers" table. However, when I execute the program, the browser does not displa ...

Enable a button or class to dynamically alter its color

Hi there! I'm new to coding and just started learning HTML and CSS. My question is: How can I change the color of buttons once they are clicked? <div class="icon-bar"> <a href="#"><i class="fa fa-search" ...

Executing Sequential Jquery Functions in ASP.Net

I have successfully implemented two JQuery functions for Gridview in ASP.Net 1. Enhancing Gridview Header and Enabling Auto Scrollbars <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script& ...

Concealing the ellipsis in the will_paginate function of Rails

I'm currently utilizing will_paginate to manage a large number of values, but I am struggling to find a way to hide the "..." portion and the page numbers following it. Here is my current setup: https://i.stack.imgur.com/f2Tt8.jpg However, what I wou ...

Is it common in Node.js to create multiple instances of "server" objects, but only connect one to a port?

After finishing "Node.js in Action", I'm now piecing together the concepts of Node.js, Connect, and Express. My inquiry revolves around the creation of servers in Node. node_server = http.createServer(); connect_app = Connect(); express_app = Express ...

Tips for eliminating white frames or borders on the Mapbox canvas map

In my current project using Angular 10, I have integrated Mapbox to display path routes. Following the standard Angular practice of splitting components, I separated the map rendering component and called it into the main map component. However, I encounte ...

Is it possible for Penthouse to retrieve critical CSS while using javascript?

I am currently utilizing the laravel-mix-criticalcss npm package to extract the critical CSS of my website. This package leverages Penthouse under the hood, and you can configure Penthouse settings in your webpack.mix.js within the critical options. The ...

What is the best way to ensure that text highlighting appears consistent on all browsers?

I am facing an issue with the appearance of text highlighting between Chrome and Firefox browsers. Is there a way to ensure consistency in the appearance across all browsers? a { text-decoration: none; font-weight: 900; font-size: 4vw !impo ...