Javascript issue

Peter_1985 2,806 Reputation points
2025-09-09T05:23:05.1266667+00:00

Hi,

Any Javascript example to show the similar button (like the following), when the mouse is on the top of the text?

User's image

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Raymond Huynh (WICLOUD CORPORATION) 2,215 Reputation points Microsoft External Staff
    2025-09-09T06:26:02.3566667+00:00

    Hello Peter_1985 ,

    I can see you want to implement hover reactions similar to Teams chat where emoji reaction buttons appear when you hover over text. Here's an example with proper emoji encoding for you:

    HTML Structure
    <div class="message-container">
    <p class="message-text">Your message text here</p>
    <div class="reaction-bar">
        <button class="reaction-btn" data-emoji="\u{1F44D}">\u{1F44D}</button>
        <button class="reaction-btn" data-emoji="\u{2764}">\u{2764}</button>
        <button class="reaction-btn" data-emoji="\u{1F602}">\u{1F602}</button>
        <button class="reaction-btn" data-emoji="\u{1F62E}">\u{1F62E}</button>
        <button class="add-reaction-btn">+</button>
    </div>
    </div>
    
    CSS Styling
    .message-container {
      position: relative;
      display: inline-block;
      padding: 8px 12px;
      border-radius: 8px;
      background-color: #f0f0f0;
      margin: 10px 0;
    }
     
    .message-text {
      margin: 0;
      cursor: pointer;
    }
     
    .reaction-bar {
      display: none;
      position: absolute;
      top: -40px;
      left: 0;
      background: white;
      border: 1px solid #ddd;
      border-radius: 20px;
      padding: 4px 8px;
      box-shadow: 0 2px 8px rgba(0,0,0,0.15);
      z-index: 1000;
    }
     
    .message-container:hover .reaction-bar {
      display: flex;
      align-items: center;
      gap: 4px;
    }
     
    .reaction-btn {
      background: none;
      border: none;
      font-size: 16px;
      cursor: pointer;
      padding: 4px;
      border-radius: 50%;
      transition: background-color 0.2s, transform 0.2s;
    }
     
    .reaction-btn:hover {
      background-color: #f0f0f0;
      transform: scale(1.2);
    }
     
    .add-reaction-btn {
      background: none;
      border: 1px solid #ddd;
      border-radius: 50%;
      width: 24px;
      height: 24px;
      cursor: pointer;
      font-size: 12px;
      display: flex;
      align-items: center;
      justify-content: center;
      transition: transform 0.2s;
    }
     
    .add-reaction-btn:hover {
      transform: scale(1.2);
    }
    
    JavaScript Functionality
    // Add click handlers for reactions
    document.querySelectorAll('.reaction-btn').forEach(btn => {
      btn.addEventListener('click', function() {
        const emoji = this.getAttribute('data-emoji');
        console.log(`Reacted with: ${emoji}`);
        // Add your reaction logic here
      });
    });
     
    // Optional: Add smooth fade-in animation
    const style = document.createElement('style');
    style.textContent = `
      .reaction-bar {
        opacity: 0;
        transform: translateY(10px);
        transition: opacity 0.2s, transform 0.2s;
      }
      .message-container:hover .reaction-bar {
        opacity: 1;
        transform: translateY(0);
      }
    `;
    document.head.appendChild(style);
    
    Key Features:
    • Hover activation: Reactions appear when hovering over the message
    • Positioning: Reactions appear above the text (like Teams)
    • Smooth animations: Fade-in effect and hover scaling
    • Click handling: Each reaction button can trigger custom actions
    • Proper emoji encoding: Uses correct UTF-8 emoji characters

    This implementation closely mimics the Teams chat behavior where reaction buttons appear on hover and disappear when you move the mouse away. Make sure your HTML file is saved with UTF-8 encoding to properly display the emojis.

    Hope this helps!


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.