Integrating jQuery Tooltip with Mouseover Event

I'm currently involved in creating a map of MIT projects for an architectural firm, and facing the challenge of maintaining the red dots mouseover state even when the mouse hovers over the tooltips that appear. Presently, the mouseover effect turns off when hovering over the tooltips.

In addition, I require the tooltips to be cleared and turned off when either the dot or the link within the tooltip is clicked. On an iPad, I observed that after clicking a tooltip link leading to a project page and then returning to the map page using the back button, the last tooltip remains open unexpectedly. This issue does not seem to occur on desktops, but it is crucial for mobile devices to have the tooltip cleared upon hitting the back button.

You can find the site I'm referring to here: and the corresponding stylesheet here:

Below is the CSS code related to the circle sprite for each button - my aim is to connect these with the tooltips. Specifically, I wish for the red circle hover state to persist when the mouse moves from red circle button 11 to its respective tooltip until it moves away from the tooltip.

#button { background:transparent url(../images/red-circle.png) no-repeat scroll 0px -2px; display:block; height:23px; width:23px; } #button:hover { background-position:0 -25px; opacity: 1; }'

Furthermore, what would be the most effective method to ensure the tooltip closes when any link within it is clicked? Unusually, on mobile devices, if you tap to activate the hover state and then click a link inside it, the tooltip remains open upon hitting the back button.

Answer №1

If you want to customize the behavior of your tooltips when shown or hidden, you can utilize the events onShow and onHide for each tooltip. Let me demonstrate how this works using your code. Below are the divs for your trigger buttons:

<div id="eleven_div" class="button-eleven" style="display: block; ">
    <a href="projects/gantt/" id="button">Button 11</a>
</div>
<div id="ten_div" class="button-ten" style="display: block; ">
    <a href="projects/table/" id="button">Button 10</a>
</div>
...

And here is the corresponding javascript:

$(".button-one").tooltip({
    position: "center right",
    delay:300,
    effect: 'slide',
    direction:'right',
    offset: [30, -12],
    slideOffset: 30,
    slideFade:'true',
    slideInSpeed:350,
    slideOutSpeed:250
});

$(".button-two").tooltip({ 
    position: "bottom left",
    delay:300,
    effect: 'slide',
    direction:'left',
    offset: [-34, 20],
    slideOffset: 30,
    slideFade:'true',
    slideInSpeed:350,
    slideOutSpeed:250
});
...

You need to change the duplicate ids inside the a-tags to classes as having duplicate ids is incorrect HTML markup:

<div id="eleven_div" class="button-eleven" style="display: block; ">
    <a href="projects/gantt/" class="button">Button 11</a>
</div>
<div id="ten_div" class="button-ten" style="display: block; ">
    <a href="projects/table/" class="button">Button 10</a>
</div>

Incorporate a callback function for showing red dots on hover. This function will add or remove a class from the triggering a-tag. Updated code:

function hovering()
{
    this.getTrigger().find("a").first().toggleClass("hovered");
}

$(document).ready(function() {

    $(".button-one").tooltip({
        position: "center right",
        delay:300,
        effect: 'slide',
        direction:'right',
        offset: [30, -12],
        slideOffset: 30,
        slideFade:'true',
        slideInSpeed:350,
        slideOutSpeed:250,
        onShow: hovering,
        onHide: hovering
    });

    $(".button-two").tooltip({ 
        position: "bottom left",
        delay:300,
        effect: 'slide',
        direction:'left',
        offset: [-34, 20],
        slideOffset: 30,
        slideFade:'true',
        slideInSpeed:350,
        slideOutSpeed:250,
        onShow: hovering,
        onHide: hovering
    });
...

Update your CSS to apply styles to the button class instead of #button:

.button {
    background:transparent url(../images/red-circle.png) no-repeat scroll 0px -2px;
    display:block;
    height:23px;
    width:23px;
    overflow:hidden;
    text-indent:-999em;
    cursor:pointer;
    opacity: 1;
    -webkit-transition: opacity 1s;
    -moz-transition: opacity 1s;
    -o-transition: opacity 1s;
}

.button:hover, .button.hovered{
    background-position:0 -25px;    
    opacity: 1;
}

.button:focus {
    background-position:0 -25px;
}

To close the tooltip when a link is clicked, add the following code after defining your tooltips:

$(".tooltip, .tooltip-brite, ... all your tooltip-classes").live("click", function() {  
    $(this).prev().tooltip().hide();
});

$(".button-two, .button-one, ... all your button-classes").live("click", function() {   
    $(this).tooltip().hide();
});

This snippet ensures that clicking either the red dot div or the tooltip box will close the tooltip.

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

Are there any alternative methods to avoid duplication of Navbar link margin classes in Tailwind CSS?

It feels really repetitive to have to add margin classes to each LI manually on a non-dynamically generated menu. It almost seems as messy as using inline style attributes... Is there a more efficient way to handle this? While it may not be a big deal fo ...

Attempting to extract information from website, successful on majority of sites but encountering issues on this particular one

We are looking to extract dividend data specifically from the Nasdaq exchange similar to this Google Sheets example. While most other URLs work without any issues, the query for this one seems to be failing. <?php $ch = curl_init(); curl_setopt($ch, C ...

How can I accurately show the server time and timezone in JS/jQuery regardless of the user's location?

Apologies for bringing up another time and timezone question related to web development. Despite numerous resources available, I am still struggling to grasp the concept of converting time between PHP and JavaScript. Here is my scenario: I aim to retrieve ...

Before sending an XHR request with Ajax, access can be granted

My goal is to implement a redirect for ajax requests. In the event of a session expiration, my backend currently redirects to the login page instead of sending data. However, I have come across discussions on StackOverflow highlighting that ajax does not h ...

What is the best way to showcase my React App.js in an HTML document?

Is there a way to display my React app file (App.Js) within my Index.html file? <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <link rel="icon" href="%PUBLIC_URL%/fav ...

Tips on automatically changing the background image every few seconds

As a newcomer to Angular and programming in general, I am facing an issue with changing the background image of my Page using the setInterval method. The intended behavior is for it to change every second, but for some reason, it changes much faster than t ...

Receiving JSON information from a web address using Javascript

I'm currently faced with a challenge in extracting JSON data from a web server. Despite the absence of errors in my code, I encounter difficulties displaying any output. Below is a snippet of the issue: <!DOCTYPE HTML> <html> <head ...

jQuery $.ajax problem encountered

When working with AngularJS, we have the ability to catch errors using the $http() service as shown below: return $http(defaultConfig).then(sendResponseData)**.catch(errorCallBack)**; On the other hand, when attempting to do something similar in jQuery: ...

Utilizing streams for file input and output operations in programming

This unique piece of code allows for real-time interaction with a file. By typing into the console, the text is saved to the file and simultaneously displayed from it. I verified this by manually checking the file myself after inputting text into the cons ...

I was unable to produce the result of the input value entered at the bottom

Is there a way to view the input and output simultaneously in my project? I've seen this done using a button, but I'm looking to achieve the same without a button. How can I do this? <input type="text" id="myText"> <b ...

"Exploring the Mini Drawer feature on Material UI brings up a whole new page for the Link

Currently, I am working on a project that involves updating stocks using Material UI. I have implemented a mini drawer from Material UI, but when I click on the menu link, it routes to a new page instead of rendering on the homepage itself. In my App.JS f ...

A method to find the sum of the final n elements in an array by employing Arr.reduceRight

I have successfully calculated the sum of the last n elements in an array using a for loop. Is it possible to achieve the same result using Arr.reduceRight instead? x = [1,2,3,4,5]; y = 0 for(let i=x.length; i>x.length-3; i--) { console.log(x[i-1]); ...

Zoom in to see the header spanning the entire width of the page

http://jsfiddle.net/CPSKa/ Whenever I zoom in on the header of my website, the line underneath it starts to shrink. Is there a way to prevent this from happening? Here is the HTML Code: <div id="main_header"> <div id="main_header_wrapper"&g ...

Ways to execute a function when a button is clicked with a shared variable?

When creating buttons in HTML to control video speed, I encountered a strange issue. After successfully implementing the buttons for one video, they only worked on a second video and had no impact on the first one. Deleting the second video seemed to resol ...

Is there a way to divide v-progress linear into 4 pieces in Vuejs, or are there alternative design options for achieving this in Vuetify 2?

I have set up a table in Vuetify 2 with a v-progress-linear component to monitor the user's remaining time. Initially, my implementation was simple like this. https://i.sstatic.net/x373G.png However, we decided to split it into 4 sections for better ...

Dynamic Bootstrap tooltip

I have a simple Javascript code snippet that I'm struggling with: $("#myinput").hover(function(){ if(condition){ $(this).tooltip({placement: "bottom", title: "mytitle"}); } ); Accompanied by its HTML cou ...

Setting the Default Value for Dropdown Options in Angular 2

Back in the Angular 1 days, I had a trick up my sleeve for setting the default option on a dropdown menu: <select data-ng-model="carSelection" data-ng-options = "x.make for x in cars" data-ng-selected="$first"> </select> But now, in ...

The log indicates that there are two distinct IP addresses associated with the user

I find that this question may be better suited for another Stack Exchange board, and I am open to migrating it there if needed. In the development of a web application, we record certain event information to assist in diagnosing any potential issues. One ...

Using three.js for creating particle systems with custom particle geometries

In my three.js project, I am working with a standard system of particles. However, I am curious if it is feasible to use different geometries for the particles, like boxes or planes. I am attempting to create falling bullet particles, but I am facing an is ...

Troubleshooting the issue: Incompatibility between jQuery .focus() and dynamically generated list items from ng-repeat in AngularJS

I am currently working on enhancing the keyboard accessibility of a website, specifically focusing on making a dropdown menu accessible via keyboard. I am attempting to establish focus on the element with the id= list-0. Below is the HTML code snippet: & ...