Hover-triggered text animation error

Hey there, I'm currently experimenting with creating an animation that involves moving text up and revealing some content when hovering over a card. It seems like everything works fine when I hover over the card, but as soon as my cursor reaches the text, it starts glitching out and moves up and down unexpectedly.

If you want to take a look at what I have so far, you can check it out here: https://codepen.io/anon/pen/qGwpaG

Below is a snippet of my code:

HTML

 <section class="section" id="black">
    <div class="container">
      <p class="display-4 d-flex justify-content-center spacing text-center light bold mt-3" id="case-head"> Make something you love.</p>
    </div>

    <div class="container">
      <div class="row no-gutters">


      <div class="col-lg-4">
          <a href="blog.html" class="hover">

            <div class="image">
              <img src="https://farm4.staticflickr.com/3766/12953056854_b8cdf14f21.jpg" class="">
            </div>
          <p class="img-text color bold">Sample - 1</p>
          <p class="img-description light">Lorem Ipsum  </p>
          <i class="fas fa-long-arrow-alt-right img-description arrow"></i> 
           </a>
        </div>
  </section>

CSS

    .img-text {
    padding: 10px;
    position: absolute;
    bottom: 0px;
    left: 16px;
    font-size: 30px;

  }

  .img-description{


    position: absolute;
    padding: 10px;
    bottom: 35px;
    left: 16px;
    font-size: 20px;
    color: white;

  }

  .image {
    position:relative;
   width: 100%;
   height: auto;
}
.image img {
    width:100%;
    vertical-align:top;
}
.image:after {
    content:'\A';
    position:absolute;
    width:100%; height:100%;
    top:0; left:0;
    background:rgba(0,0,0,0.8);
    opacity:0;
    transition: all 0.5s;
    -webkit-transition: all 0.5s;
}
.image:hover:after {
    opacity:1;
}
.color
{
  color: white!important;
}

JS

$('.img-description').hide();

$(".hover").mouseover(function() {
    $(this).find(".img-text").animate({ bottom: 100 },100);
    $(this).find('.img-description').show();
})

$(".hover").mouseout(function() {
    $(this).find(".img-text").animate({ bottom: 8 });
    $(this).find('.img-description').hide();
})

Answer №1

Ensuring that only the parent element triggers the events is essential. If you use mouseover/mouseout, any child element can unintentionally trigger these events which may not be desired.

To rectify this issue, consider using mouseenter/mouseleave or implement the hover shortcut:

$(".hover").hover(
  function() {
    $(this).find(".img-text").animate({ bottom: 100 }, 100);
    $(this).find(".img-description").show();
  },
  function() {
    $(this).find(".img-text").animate({ bottom: 8 });
    $(this).find(".img-description").hide();
  }
);

https://codepen.io/anon/pen/mYgxWv

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

Why does Socket.IO seem to be registering two clients instead of just one when there is only one connection

When using my app, the user first lands on the home screen where they can select their username. They then proceed to another page and from there, navigate to the room entry page. The issue I'm facing is with a specific section of my code that update ...

Encountering numerous errors when attempting to incorporate lottie-web into my JavaScript file

I am in the process of creating a unique audio player for my website utilizing HTML, CSS, and JavaScript. I encountered some challenges while trying to get it to work effectively on Codepen as well as my text editor. The animations were not functioning pro ...

Tips for wrapping text within a span element that is positioned absolutely

Need a long string for the bullet text as shown in the code, they can't be separate words. Having trouble with overflow auto, it's cutting off the bullet text. The bullet text must remain in absolute position. How can I make the text wrap to t ...

What is the best way to transmit a variable name along with its value to the server, and then successfully obtain a computed response in

I am a beginner in the world of Wordpress and plugins, but I have a decent understanding of PHP, JavaScript, and HTML. Recently, I created a plugin for Wordpress that generates a page (form) to gather information about product specifications. Although it c ...

Problems with the Chosen property of MenuItem within Material-UI

The MenuItem's "selected" property does not seem to be functioning correctly within the Select component. For reference, please visit https://codesandbox.io/s/9j8z661lny I have attempted to use comparison with the Id, and even tried using selected={t ...

Adjust the header's alignment to seamlessly coincide with the uppermost part of the

I'm encountering this peculiar issue with a website I recently started designing. My aim is to make the header perfectly aligned with the top of the page. However, despite my attempts, there persists a stubborn gap that measures around 20px, defying a ...

Uncover concealed words within PDF documents

While incorporating PDF.js to display LaTeX typeset PDF files on my website, I encountered an issue. I have concealed specific text in the PDF, but it remains searchable when viewed in Acrobat Reader. Is there a method to search for hidden text using PDF ...

Tips for generating multiple HTML hyperlinks using a for loop in a Chrome extension

function createDropDown(){ const tree = document.createDocumentFragment(); const link = document.createElement('a'); for(let index = 0; index < urlList.length; index++){ link.appendChild(document.createTextNode(urlList[index])); ...

Center align `div 1` with CSS and right align `div 2`

Take a look at this code snippet: http://jsfiddle.net/zygnz/1/ <div class="container"> <div class="left"> LEFT </div> <div class="right"> RIGHT </div> </div> Is i ...

Creating a string-based template that can be included in Django

I need to create a list of clickable links for my navigation bar with the URLs provided using the url-tag. To achieve this, I have a list of dictionaries containing all the necessary information for each link, and I am creating a template string with them ...

Switching an array with a single string in MongoDB

I'm facing an issue with grouping data in mongoDB and wondering if there's a way to transform an array into a string. The objects included in $lookup are currently displayed in an array format, but I need them in a single string. Here is my code ...

The controller persists in its loop as it utilizes $state.go

As a newcomer to Angular, I am uncertain if this is the most effective solution. Within my state/route, there is a button that triggers the following function when clicked: _this.foo = function () { save(); $state.go("next"); } The issue arises w ...

Ways to develop tests for functions specific to my scenario

Currently, I am attempting to implement a timeout function test within my application. Within the controller: $scope.$watch('toy',function(toyVar){ if(toyVar == 1) { //perform actions } else { $timeout(f ...

Troubleshooting guide: Issues with compatibility between Angular 5 and Bootstrap 4

Upon creating a fresh Angular 5 project, I decided to integrate Bootstrap 4.0.0 using the guidelines provided on the Angular CLI GitHub page. Following the instructions, I utilized 'npm install bootstrap' to incorporate Bootstrap into my project. ...

Transferring information from a component that includes slot content to the component within the slot content

This task may seem complex, but it's actually simpler than it sounds. I'm struggling with the correct terminology to enhance the title. I need to transfer data from a component that includes slot content to that slot content component. In partic ...

Jade Compilation with Gulp

Currently utilizing gulp-jade, I have encountered an error with a particular template: 557| 558| > 559| 560| .tabs-wrap(ng-show="eventExists"): .contain-center 561| 562| #room-tabs-contain.contain-disable.contain: .contain-center unexpec ...

Discovering the power of VBA in combination with Selenium to pinpoint and interact with a particular cell within a table

I am attempting to access a specific cell within a table on a webpage. The cell I need to reach has an id of "flowTile_6". It is highlighted below. I have tried multiple methods, but all resulted in errors. One approach I attempted was using the followi ...

Tips for establishing a ref while utilizing React.cloneElement with a functional component

As I create my own Tooltip component, I encountered a particular issue - Function components are unable to receive any refs This is what my code currently looks like Here's the part of the Component that contains the Tooltip: <Tooltip title=&qu ...

Is there a way to activate the window load event within this Jest test scenario?

I'm in the process of setting up my first Jest test for DOM manipulation and jQuery in my Rails project. Right now, I'm facing a basic challenge of ensuring that imported JavaScript functions are functioning as expected. In order to tackle this ...

Gliding along a div and concealing it out of view, making it seem like it has disappeared

I attempted to slide down the ".preloader" div after a 2-second delay using JQUERY, but I couldn't get it to work as expected. I didn't want to use a toggle button for this effect. I also experimented with creating an animation using @keyframes, ...