UserHoverCard in the style of Tumblr

Hey guys, I'm facing an issue with ajax hover effects. I'm attempting to create a userHoverCard similar to Tumblr's functionality. However, the hover animation isn't working properly when I integrate it with ajax.

The hover effect is functional in this DEMO which only uses CSS without ajax. If you check out the demo, you'll notice that hovering over images triggers the display of .p-tooltip with a smooth animation effect.

However, if you visit this DEMO on my test page, you'll see that hovering over an image doesn't trigger the animation effect for .p-tooltip.

Here's the HTML code snippet:

    <div class="p-tooltip"></div>
    <div class="summary" data-id="25">
      <a href=#" class="profile-ava"></a>
    </div>
    <div class="summary" data-id="20">
      <a href=#" class="profile-ava"></a>
    </div>
    <div class="summary" data-id="25">
      <a href=#" class="profile-ava"></a>
    </div>

This is the ajax code I'm using:

$(document).ready(function() { 

        function showProfileTooltip(e, id){ 
           e.append($('.p-tooltip').css({ 
             'top':'20', 
             'left':'80' 
             }).show()); 
            //send id & get info from get_profile.php 
             $.ajax({
             url: 'get_profile.php?uid='+id,
             beforeSend: function(){

             $('.p-tooltip').html('Loading..');
             },
             success: function(html){ 
             $('.p-tooltip').html(html); 
             } 
           }); 
         } 

        function hideProfileTooltip(){ 
        $('.p-tooltip').hide().fadeIn('fast'); 
         } 
        $('.summary a').hover(function(e){ 

          var id = $(this).attr('data-id'); 
          showProfileTooltip($(this), id); 

          }, function(){ 
          setTimeout(function(){ 
          hideProfileTooltip(); 
          },2000); 
         });
    });

And here's the corresponding CSS code:

[CSS CODE GOES HERE]

If anyone can offer some assistance, that would be greatly appreciated!

Answer №1

After coming up with a smart solution, I devised a mask that initially hides the image until the HTML is fully loaded. Once the z-index is lowered, the hover CSS effect takes place smoothly. The hover JavaScript function is applied to the container.

Check out the FIDDLE

.summary {
    margin: -50px auto 0;
    width: 50px;
    height: 50px;
    position: relative;
    z-index: 0;
}
.summary-mask {
    margin: 50px auto 0;
    width: 50px;
    height: 50px;
    position: relative;
    z-index: 1;
}
.loaded .summary-mask {
    z-index: -1;
}

HTML

<div class="the-container">
    <div class="summary-mask"></div>
    <div class="summary" data-id="100"> <a href="http://kraigo.tumblr.com/" class="profile-ava"></a>

        <div class="user-container"></div>
    </div>
</div>

JS

var response = '<div class="p-tooltip"> <div class="profile-header"></div> <div class="profile-navigation"> <a href="http://kraigo.tumblr.com/" class="profile-action">Follow</a> <p class="profile-nick"> <a href="http://kraigo.tumblr.com/">Page Name</a> </p> </div> <div class="profile-ava"></div> <div class="profile-info"> <h1 class="profile-title">Username</h1> <p class="profile-description">Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy ..</p> </div> <ul class="profile-items"> <li></li> <li></li> <li></li> </ul> </div>';

$(document).ready(function () {

    function showProfileTooltip(e, id) {
        //send id & get info from get_profile.php 
        $.ajax({
            url: '/echo/html/',
            data: {
                html: response,
                delay: 0
            },
            method: 'post',
            success: function (returnHtml) {
                e.find('.user-container').html(returnHtml).promise().done(function () {
                    $('.the-container').addClass('loaded');
                });
            }
        });

    }

    function hideProfileTooltip() {
        $('.the-container').removeClass('loaded');
    }
    $('.the-container').hover(function (e) {

        var id = $(this).find('.summary').attr('data-id');
        showProfileTooltip($(this), id);

    }, function () {
        hideProfileTooltip();
    });
});

Answer №2

While displaying the card, only the loading message is visible. The transition does not occur when you add content to the card because it is not a CSS modification.

If you hold off on revealing the card until the content has loaded, then there will be something to animate.

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

What is the best way to create a footer in this scenario and is there a method to perfectly center an

What is the best way to position the footer at the bottom of the page without overlapping the top content? Is there a method to center both the height and width of the header element on the page? Can you review the layout of this webpage and provide feed ...

React is throwing an error message stating that setCount is not a valid function

Getting an error saying setCount is not a function. I am new to this, please help. import React, { memo, useState } from "react"; export const Container = memo(function Container() { const { count, setCount } = useState(0); return ( ...

Verify the changing text within a Span tag with the use of Selenium in Java

Can anyone assist me in creating a logic to verify a dynamic text? The text within the tag below is constantly changing (to 6 distinct words), and I need to validate if those 6 unique words match the expected text. Is there a method to do this verification ...

Troubleshooting the ineffectiveness of appending a table using a loop

In my jQuery code, I am looping through a result set using $.each and attempting to append data to a table: $.each(result, function (y, z) { $table.append("<tr>"); $table.append("<td>" + y + "</td>"); ...

Library for Typescript in Microsoft MakeCode Minecraft

Just started my journey in the world of Minecraft and I am currently trying to navigate through using javascript within the game. Specifically, I have some questions pertaining to javascript objects as I delve into the Windows 10 version of Minecraft. I am ...

What is the correct way to import CSS styles globally in Vue?

My scss file contains a few classes. Each time I save the file, corresponding css files are generated. My initial thought was that I only need to import the resulting css in my main.js file to utilize it throughout my entire application. For example, let&a ...

Modifying theme colors dynamically during program execution

Currently, I am working on implementing a remote styling feature. I have been unable to figure out how to modify the colorPrimary value after the activity has been created and the remote style is fetched through the API. While I understand that theme styli ...

Was not able to capture the reaction from the Angular file upload

I've been attempting to upload a single file using the POST Method and REST Calling to the server. Despite successfully uploading the module with the code below, I encounter an error afterwards. Is there anyone who can lend assistance in troubleshooti ...

Leveraging jquery to retrieve measurements of concealed components

I have a unique twist on a common question that I hope will provide new insight: Currently, I am facing a situation where I need to use .show() on elements that are initially rendered with display: none. Ideally, I would like to show all elements on the p ...

Tips for extracting the remaining value of an object within an array

Consider the following data structure: { "restaurant": { "categories": [ { "name": "Italia" }, { "name": "Modern" } ], } } When trying to acces ...

Issues encountered when trying to use the export default syntax in Vue components

Programming Issue I attempted to execute the provided code, but unfortunately, it does not work and no output is visible in the browser. Is there an alternative method for writing code within <scripts setup> </script>? I have understood that f ...

AngularJS: Retrieving marker coordinates post map drag action

My CSS displays a marker on the map and allows users to drag a map like Uber. Now, I need help getting the current location of the marker. I have included style.css, DeliverCtrl.js, and HTML code. Can anyone assist me with this? style.css map{ displa ...

Transform current JSON data into formatted JSON format using JavaScript or TypeScript

I have a JSON structure that needs to be reformatted in order to meet the requirements of an external service. Although the current format is complex and cannot be altered, I need to modify it to match the desired output for the external service. Current ...

Updating by clicking with auto-prediction feature

I have implemented an autosuggestion feature to display results from a database table while typing in an HTML field, and I am looking to utilize JavaScript to post another value from the same row where the autosuggested values are stored. https://i.stack. ...

Insert data into the corresponding input box by selecting a checkbox with the same class individually

How can I place the value of checked checkboxes into different input boxes with the same class? Currently, the value of all input boxes with the same class reflects the value of the checked checkboxes. I am looking for a way to assign the value in input bo ...

Challenge with Jquery's slideToggle functionality when used with <H3> elements

I'm looking to make a small amendment to the jQuery code below. (Take a look at the DEMO) In the demo, you'll see that Heading One slides up and down as expected, but Heading Two and Three do not. The only difference is that I added an extra div ...

What is the variance in performance between the sx prop and the makeStyles function in Material UI?

I recently started delving into Material UI and learned that it employs a CSS in JS approach to style its components. I came across 2 methods in the documentation for creating styles: First, using the sx prop: <Box sx={{ backgroundColor: 'green& ...

"Retrieve a variable from the code-behind file and use it in the ASPX

I am attempting to retrieve a variable from the code behind page and display it in an ASPX page with HTML formatting. Here is the code I am using: Note: I have assigned a value to a StringBuilder object, stored it in a variable, and now I am trying to acce ...

Extracting specific keys from JSON data

I am working with an array named cols: var cols = ["ticker", "highPrice", "lowPrice","lastPrice"] // dynamic The JSON data is coming from the backend as: info = {ticker: "AAPL", marketCap: 2800000000, lowPrice: 42.72, highPrice: 42.84} If I want to sel ...

Switch between multiple unordered lists (ul) so that when one list is clicked, the other lists reset to their initial state as though they were never

When I click on the first item in the ul list, it should slideToggle() to show its corresponding items. Similarly, when I click on the second item in the ul list, its items should slideToggle(), but the first ul list remains visible as well. What I am tryi ...