Flashing hover popup issue with links using jQuery

I successfully created an experiment using the code below, which is functioning more or less as intended. The goal was to have a link that opens a popup on hover while dimming the other links.

Check out the code here

The current issue I am facing is that when the popup appears above the link, it starts to flicker, most likely due to confusion within the "hover" function. How can this be resolved?

<div class="container">
 <a data-target="boxid1" class="link-box"><img src="https://via.placeholder.com/350x65"></a>
</div>
<div class="container">
 <a data-target="boxid2" class="link-box"><img src="https://via.placeholder.com/350x65"></a>
</div>
<div class="container">
 <a data-target="boxid3" class="link-box"><img src="https://via.placeholder.com/350x65"></a>
</div>


<div id="boxid1" class="modal-box">
 Content Box 1
</div>
<div  id="boxid2" class="modal-box">
 Content Box 2
</div>
<div  id="boxid3" class="modal-box">
 Content Box 3
</div>
.container { background: black; color: white; padding: 50px; float: left; border: 1px solid red; margin: 5px; text-align: center; }
.modal-box { display: none; position: absolute; top: 50%;   left: 50%; transform:translate(-50%,-50%); background: blue; color: white; padding: 25px; width: 250px; height: 200px; }
.dim { opacity: 0.3; }
$(function(){

    $('.link-box').hover(function(e){
    var $parent=$(this).closest('.container');  
            $('.container').not($parent).addClass('dim');
      $('#'+$(this).attr('data-target')).show();},
      
          function(e) {
            var $parent=$(this).closest('.container');  
            $('.container').not($parent).removeClass('dim');
                 $('#'+$(this).attr('data-target')).hide();
            }
  );

});

Answer №1

Indeed, the issue arises when the cursor hovers over the popup. Moving the popup inside the anchor link-box resolves this problem.

$(function(){

    $('.link-box').hover(function(e){
    var $parent=$(this).closest('.container');  
            $('.container').not($parent).addClass('dim');
      $('#'+$(this).attr('data-target')).show();},
      
          function(e) {
            var $parent=$(this).closest('.container');  
            $('.container').not($parent).removeClass('dim');
                 $('#'+$(this).attr('data-target')).hide();
            }
  );

});
.container {
  background: black;
  color: white;
  padding: 50px;
  float: left;
  border: 1px solid red;
  margin: 5px;
  text-align: center;
}
.modal-box {
  display: none;
  position: absolute;
  top: 50%;
  left: 50%;
  transform:translate(-50%,-50%);
  background: blue;
  color: white;
  padding: 25px;
  width: 250px;
  height: 200px;
  z-index: 10;
 }
.dim {
  opacity: 0.3;
 }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="container">
 <a data-target="boxid1" class="link-box"><img src="https://via.placeholder.com/350x65">
 <div id="boxid1" class="modal-box">
 Content Box 1
</div>
 </a>
</div>
<div class="container">
 <a data-target="boxid2" class="link-box"><img src="https://via.placeholder.com/350x65">
 <div  id="boxid2" class="modal-box">
 Content Box 2
</div>
 </a>
</div>
<div class="container">
 <a data-target="boxid3" class="link-box"><img src="https://via.placeholder.com/350x65">
 <div  id="boxid3" class="modal-box">
 Content Box 3
</div>
 </a>
</div>

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

Align pandas data frame to the right within a Flask application

My current project involves creating an API in Flask. One of the requirements is to display a pandas dataframe right next to the upload button on the web page. While I have been able to find information online about justifying column headers or text, I hav ...

Tips for enhancing the "Eliminate render-blocking resources" score on the Lighthouse report for Progressive Web App (PWA) optimization

Check out my first attempt at a PWA here: My goal is to achieve a perfect 100% in Lighthouse for all categories :) https://i.sstatic.net/9Ql9r.png Although I've read the "Learn More" page, I'm still struggling with how to implement Bootstrap C ...

The filename is not displaying in the file input field within the bootstrap framework

Below is the HTML code I am working with: <head> <link rel="stylesheet" href="./Depd/bootstrap.min.css"> </head> <body> <div class="input-group"> <div class="custom-file"> <input type="file" class="c ...

Ways to retrieve the CSS class names associated with an element

To determine if an element has been selected, I rely on checking for the presence of an additional CSS class called "selected" that is added to the element The structure of my element is as follows: <div class="b-wide-option" data-bind="css: { selecte ...

Tips for ensuring only digits can be entered in a textbox on Firefox

Having trouble validating digits in a textbox on both IE 9 and Firefox versions 4 & 5. Does anyone know how to solve this issue? I've attempted the solutions provided in previous questions, but I'm still encountering problems. My goal is to only ...

Having four videos displayed on one webpage can cause the browser to function at a slower

I have videos that are around 30 seconds long and 15mbs. I'm wondering if it's feasible to include them on a page or if I should opt for cover images instead. I would like to use the video as a separator similar to the design showcased at Does a ...

What could be causing the svg to not be visible inside the div?

I am struggling to display an SVG element within a div as it is not visible at all. Can someone help me make the SVG visible in the div? Here is a link to the code: http://codepen.io/helloworld/pen/HjkhK <div style="height:100px;background:yellow;"> ...

How can I attach the input value that has been selected to another div using Ajax AutoComplete for jQuery?

Greetings, I am currently utilizing the Ajax AutoComplete for jQuery library. Within this library, there are 2 demos available. In the first demo titled "Ajax auto-suggest sample (start typing country name)", when a country is selected from the dropdown, ...

Animating Font Awesome content through CSS transitions

I am looking to animate a font awesome pseudo element on my website. Below is the HTML code I am working with: <li class="has-submenu"> <a onclick="$(this).toggleClass('open').closest('.has-submenu').find('.submenu&a ...

What could be the reason for JavaScript code successfully exporting to Excel using the old office extension .xls but encountering issues when trying to export

I am currently working on exporting an HTML table to Excel using JavaScript. I have encountered an issue where it does not export to the newer version of Excel with the xlsx extension. However, it works fine and exports to older versions of Excel with the ...

What is the best way to showcase a half star rating in my custom angular star rating example?

component.ts import { Component } from '@angular/core'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { projectRating ...

Fade in a CSS class using jQuery

I'm attempting to incorporate a basic fadeIn() CSS effect on specific objects that are tagged with the "button" class. My goal is to have the "hoverbutton" class fade in when the object is hovered over, and then fade out when the cursor moves away fro ...

Question about jQuery's XHR

Currently working on a basic jQuery script to parse JSON data and format it. However, I keep encountering an error in Chrome that says: Resource interpreted as Script but transferred with MIME type text/html. After researching on SO, it seems to be a comm ...

Optimizing React+ReactRouter web app loading times by efficiently splitting and loading CSS using WebPack

I am encountering a delay in the initial loading of my web app, even after implementing various improvements like using only critical CSS during server side rendering. Unfortunately, post-SSR, React still generates unnecessary CSS rules that are not utiliz ...

What is the CSS technique to make text wrap around an image, similar to the layout seen in certain newspapers?

I am looking for a way to have my images wrap with text align in this specific layout: <html> text text text text text <br> text text text text text <br> ______________ text text text <br> image | text text text <br> i ...

Uncover a one-of-a-kind identifier within the jQuery each() method

Is there a way to create a selector that can accurately refer to the current targeted DOM element (referred to as this) within an iteration of a jQuery each loop? For example, if the selector were #abc, .xyz and the HTML source was: <body> ...

The Datatables render function seems to be inactive

$("[data-manifest-table]").DataTable({ "processing": true, "serverSide": true, ajax: { url: "LoadManifestData", type: "POST", data: { FilterItem: new FilterItem($("[data-statuses]").val(), $("[dat ...

Obtain base64 representation of a file using plupload file uploader

I am currently utilizing the Plupload Uploader. My objective is to convert the uploaded file to base64 and transmit it within a SOAP envelope. I have successfully created the envelope and utilized my web-service. However, I am wondering how I can retrieve ...

Conceal the complete <div> in the event that the <table> contains no data

My task involves managing a div containing a table. The goal is to hide the div if it has no value or is empty, and then show it again once it has a value. <div class="container" id="main_container"> <table id="my_tabl ...

Attempting to execute this function to verify the presence of matching email addresses within the database

function checkEmail(){ var email = $("#email").val(); var xmlhttp = new XMLHttpRequest(); var url = serverURL() + "/checkIfEmailExists.php"; url += "?email=" + email; xmlhttp.onreadystatechange=func ...