jQuery Animation Issues with Hovering Divs and Images

I am encountering an issue with how my .animation is functioning with JQuery.

There is an image containing showthis() and hidethis() functions:

function hidethis() {
    $('#info1').animate({
        bottom: '-150px',
    }, 100);
}
function showthis() {
    $('#info1').animate({
        bottom: '0px',
    }, 500);
}

The components include an image on the page and a div with position: fixed; overlaying the image acting as a show/hide information tab.

Below are the styles for each element:

.slide img {
    position: absolute;
    top: 0px;
    left: 0px;
}
.info {
    position: fixed;
    bottom: -150px;
    left: 0px;
    width: 527px;
    height: 100px;
    background-color: white;
    padding: 15px;
    opacity:0.9;
}

JQuery is triggered by onmouse events within the image:

onmouseover="javascript:showthis();" onmouseout="javascript:hidethis();"

The challenge:

The floating div above the image (appearing whenever the visitor hovers their mouse over the image) is conflicting with the onmouseout event on the image. When hovering over the image, the div shows up. However, if I hover over the div while still hovering over the image, the div hides and the animation starts repeatedly toggling while I continue moving my mouse where the div appears. How can this be resolved?

Answer №1

It is recommended not to place the event handler directly on the image itself. Instead, consider placing it on a parent element to prevent issues when the mouse moves from the image to the .info element. Here's an example:

HTML

<div class="slide">
    <img src="someimage.png" />
    <div class="info">Some information</div>
</div>

JS

$('.slide').on({
    mouseenter: showContent,
    mouseleave: hideContent
});

Additionally, there seems to be inconsistency in using #info1 in the functions and .info in the CSS. Please clarify this.

FIDDLE

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

Here's a new take on the topic: "Implementing image change functionality for a specific div in Angular 8 using data from a loop"

I need to create a list with dynamic data using a loop. When I click on any item in the list, I want the image associated with that item to change to a second image (dummyimage.com/300.png/09f/fff) to indicate it's active. This change should persist e ...

Detecting the Escape key when the browser's search bar is open - a step-by-step guide

One feature on my website is an editor window that can be closed using the Escape key. The functionality is implemented in JavaScript: $(document).keyup( function(e) { // Closing editor window with ESCAPE KEY if(e.which == 27) { // Clic ...

What is the best way to vertically center all content, including borders, within the columns?

To view the codepen for reference, please click on the following link: http://codepen.io/rezasan/pen/apvMOR I am attempting to align all the content within the columns (Date, Title, and Button, including the separator) vertically. I have tried using displ ...

Is there a way for jQuery.live to prevent the browser from navigating to a link?

I'm attempting to implement $().live in order to enhance a website, however it continues to follow the href. Here is code very similar to what I am using (a.class, span inside a). <a class="test" href="http://google.com"><span>test</sp ...

External Submit button malfunctioning when attempting to submit two distinct forms

I'm currently working on a program to add items to the cart, and I need to include product attributes like colors and sizes in the process. However, I seem to be encountering an issue where only one form is submitted when using jQuery's submit(), ...

Submitting a page with PHP, Ajax, and JSON

Need help with making an Employee search functionality in my business using Ajax. After submitting the form, I want to load employee details using jQuery-based Ajax. Here is the code for searching employees. The problem I'm facing is that after submi ...

My browser isn't triggering the jQuery change event, although it does work in jsfiddle

Whenever a textbox is changed, I want a specific function to be executed automatically. The code snippet below demonstrates my approach: var div = document.getElementById("tree"); var input = document.createElement('input'); input.id = 123; i ...

Inserting content at the footer of the webpage

I managed to center 2 divs using the power of flex, and now I want to introduce a third div at the bottom of the page, just like in the image below: https://i.sstatic.net/pQleWm.jpg (I need the first two divs to stay centered based on their parent elemen ...

Is there a way to change the visibility of a form element within a directive with the help of

Consider a scenario where you have a basic form as shown below: <form ng-submit="methods.submit(formData)" ng-controller="diamondController" name="diamond" novalidate> <help-block field="diamond.firstName"></help-block> <input ...

Transmit data to PHP via Ajax without needing to redirect

Struggling to figure out how to send an image from ajax to PHP after uploading it in a form? Here is the ajax call you can take a look at: var dataString = 'city='+ city_push + '&venue=' + venue_push + '&title=' + ti ...

Integrate jQuery-ui into your Angular 5 application

Having some trouble integrating jquery-ui into my Angular 5 project. I need to use a feature that requires jquery-ui, but I keep encountering this error: TypeError: WEBPACK_MODULE_10_jquery(...).droppable is not a function I initially attempted to plac ...

How can I adjust the padding and width attributes of the mat-menu in Angular 5

Today, I am struggling with a piece of code. Whenever I click on the Details button, it is supposed to open a mat-menu. However, for some reason, I cannot seem to adjust the padding or width of the menu: <div id="box-upload" [hidden]="hiddenBoxUpload" ...

Retrieving Value from Dynamic Content Using jQuery `.keypress()` and `.delegate()`

I have encountered an issue with my code that is unable to retrieve the value of a specific ID on the .keypress function after using .delegate. The ID and other contents are generated dynamically through an AJAX call. $(document).delegate('.edit_ ...

Why aren't jQuery events triggering following an AJAX request?

I have created a website that utilizes fading effects to transition between sections while loading new content. One of the features includes enlarging an image upon clicking, which is achieved through a jQuery event trigger. The issue I am facing is that ...

Exploring how CSS affects backgrounds in the Google Chrome browser

Having an issue with the background on my website. In Firefox and other browsers, the background appears much lighter and whiter compared to Chrome. This is the CSS code for my background: body {background:#ffffff url(../../images/background.jpg); direct ...

Incorporating Blank Class into HTML Tag with Modernizr

Currently, I am experimenting with Modernizr for the first time and facing some challenges in adding a class to the HTML tag as per the documentation. To check compatibility for the CSS Object Fit property, I used Modernizr's build feature to create ...

Notification box appears only when closing the window, not when reloading the page

I've been trying to find a way to remind my users to log out before closing the window. I found this code that seems to work: window.onbeforeunload = confirmExit; function confirmExit() { return "It's best to log out before you close this pa ...

Creating a WordPress post popup using Ajax with SimpleModal and jQuery

I tried to follow the instructions provided in this tutorial but unfortunately, I couldn't get it to work. This is the process I followed: 1 / Including in the header <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ...

What is the best way to ensure that an image in the navbar changes when hovered over?

In my quest to enhance my skills, I am currently trying to figure out how to create a hover effect on an image within the navbar. My objective is to have the div with the ID of "pic-index" react to hovering over the "HOME" link in the navbar and change the ...

Using jQuery to dynamically swap out <tr> tags and all the elements inside of them

In order to enhance user experience, I am looking to automatically fill in certain form elements within a table when a link is clicked. The intention is for the fields to populate with predefined values and then convert into HTML paragraph elements, preven ...