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

VueJS Element Library's date picker feature returns dateTime values with their corresponding time zones attached

I'm currently utilizing a date picker from The expected format for the date should be: yyyy-MM-dd However, the actual returned date format is: Thu Apr 20 2017 00:00:00 GMT+0530 (India Standard Time) This is the code snippet I've used: & ...

Sending a JSON array in an AJAX request results in receiving null values in an MVC application

I've been trying to send an array of JSON objects to my controller action, but it keeps showing up as null. Here's the JavaScript code I'm using: function UpdateSelected() { var items = {}; //Loop through grid / sub grids and crea ...

You cannot utilize Lesson as a JSX Component in Next JS TypeScript

Below is my updated page.tsx code: import Aspects from '@/components/Aspects'; import FreeForm from '@/components/FreeForm'; import Lesson from '@/components/Lesson'; import React from 'react'; import { Route, Route ...

Encountering the "Local resource can't be loaded" error when attempting to link a MediaSource object as the content for an HTML5 video tag

I'm attempting to make this specific example function properly. Everything runs smoothly when I click the link, but I encounter an error when trying to download the HTML file onto my local machine and repeat the process. An error message pops up sayi ...

PHP ajax needs to solely showcase error messages upon form submission

When I submit my form data to a PHP file, it checks for any errors. However, it also returns success before redirecting through AJAX. My goal is to only display an error message if there is one, and if successful, redirect to another page. AJAX: $("#msf ...

How can you conceal an HTML element when the user is using an iOS device?

I need the code to determine if a user is using an iOS device and, if not, hide the HTML input type "Play" button. So, I'm uncertain whether my iOS detection is correct, the hiding of the "Play" button in the code, or both: <!DOCTYPE html> < ...

How to trigger a force reload on a VueJS route with a different query parameter?

Is there a method to refresh the page component when two pages utilize the same Component? I have encountered an issue where the router does not reload and the previous edit values persist. { path: "/products/new", component: ProductPage, meta: { ...

Ways to prevent npm script from running automatically in the background

When working with npm scripts, I have a situation where some tasks need to run in parallel. My setup looks something like this: ... scripts: { "a": "taskA &", "preb": "npm run a", "b": "taskB" } ... Everything works well so far! But I am won ...

What is the method of utilizing shared services when the controllers do not rely on any shared services?

Let's imagine a scenario where there is a module containing only one factory, which serves as the shared service. angular.module('sharedService', []) .factory('sharedSrv', sharedService) function sharedService() { var numbe ...

retrieve JSON object from deferred response of AJAX request

After utilizing Ajax to send an item to a SharePoint list, I aim to incorporate the jsonObject received in response into a list of items. Located in AppController.js $scope.addListItem = function(listItem){ $.when(SharePointJSOMService.addListIte ...

A step-by-step guide on ensuring mandatory completion of all input fields prior to form submission

I'm new to JavaScript and I need some help. Currently, I am trying to implement input field validation using pure JavaScript for a form. However, I am facing an issue where the "Required" message only appears next to the last name input. What I want ...

I found myself puzzled by the error message "Module protobufjs not found."

I am currently utilizing the node library known as node-dota2. I have completed all the necessary steps required by node-dota2, as outlined on this site: https://github.com/Arcana/node-dota2#installation-and-setup 1. Installed it using npm 2. Created a fil ...

Is it possible to create a personalized serialize form when sending an AJAX POST request

How can I format form data on an AJAX POST request differently than the default $("#formid").serialze()? The current result is not suitable for my needs, as it looks like this: `poststring="csrfmiddlewaretoken=bb9SOkN756QSgTbdJYDTvIz7KYtAdZ4A&colname= ...

PHTML file IIS handler

I was surprised by the lack of online results when searching for a solution to my issue. In my local PHP project, I am encountering problems with PHTML files not being parsed correctly by IIS. The 'phtml' type is not included in the module mappin ...

What causes my scene to appear black until OrbitControl is activated in ThreeJS?

What causes the scene in ThreeJS to only appear after clicking and moving the cursor? The page remains black until I interact by clicking and moving, then everything shows up. I'm stumped on what the issue could be. Any assistance would be greatly ap ...

I am in search of a clean and efficient method to modify the class of a link that triggers an HTMX request in Django. Perhaps something like "auto-refresh" or a similar solution would be ideal

I've encountered an issue with HTMX in Django. The page consists of two main components: a list of categories and the content that is displayed when a category is clicked. Initially, everything was working smoothly with standard htmx functionality. H ...

Stop images from appearing transparent when placed inside a transparent div

My issue is clearly visible in this image: The div element is transparent and affecting the images inside it. Below is my HTML code: <div id="cselect" style="position: absolute; top: 99px; left: 37px; display: block;"> <div class="cnvptr"> ...

How do I disable scrolling while the animation is running in CSS?

Is there a way to disable scrolling while animating in CSS without using overflow:hidden on the body tag? ...

Steps to Create an HTML Text Box that cannot be clicked

Does anyone know of a way to prevent a text box from being clicked without disabling it or blocking mouse hover events? I can't disable the text box because that would interfere with my jQuery tool tips, and blocking mouse hover events is not an opti ...

The error message 'Blob is undefined' pops up when trying to use react-media-recorder in an Astro project

I'm currently working on a project that involves Astro and React components, and I'm attempting to integrate react-media-recorder. The code I have is quite simple, just a React component placed within an Astro page: import { useReactMediaRecorde ...