Stack Overflow tags - How do they display info on mouse over?

前端 未结 5 1001
小蘑菇
小蘑菇 2021-01-27 05:31

At the event of mouse over each Stack Overflow tag displays an information box beneath itself. As long as the mouse is over the tag or over the info box, it continues to be visi

相关标签:
5条回答
  • 2021-01-27 05:56

    Without being more specific all I can give you is a general idea of how it works.

    The mouseover will trigger an AJAX request (probably after a short timer countdown in order to keep it firing until the pointer has been over the tag for a short time) which queries the SO database about the tag in question. If returns some kind of response, either a HTML fragment which is injected directly into the DOM, or an XML or JSON encoded data block which is used to populate an element which is injected into the DOM. The mouseout event will remove the element from the DOM. I would imagine the AJAX response is also held in a memory cache by the javascript that manages it so that the same data doesn't get repeatedly requested.

    0 讨论(0)
  • 2021-01-27 05:57

    Look at some tooltip plugins for jQuery. As for the receiving of the HTML for the tooltip, just look at some simple $.ajax examples in the jQuery documentation.


    Tooltips

    • 30 Stylish jQuery Tooltip Plugins For Catchy Designs
    • 10 Excellent ToolTip Plugins with jQuery
    0 讨论(0)
  • 2021-01-27 06:05

    I would recommend Tooltip for something like that.

    0 讨论(0)
  • 2021-01-27 06:11

    Add an event listener to the mouseover DOM event to display the info box. Add an event listener to the mouseout event to hide the info box. See Mouse event types for details. Retrieve the information that you want to display in the info box via XMLHttpRequest.

    0 讨论(0)
  • 2021-01-27 06:15

    One of the many jQuery tooltip plugins:

    http://jquery.bassistance.de/tooltip/demo/

    Also, I think SO uses AJAX to load the information inside the tooltip, but you don't have to do that.

    0 讨论(0)
提交回复
热议问题