Plain JavaScript tooltip

前端 未结 5 2024
渐次进展
渐次进展 2020-12-08 01:16

I am trying to make a tooltip in plain JavaScript which is shown on hover. Like the one in Stack Overflow on hover over the profile name a div is s

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-08 01:43

    Fix for the original code

    I was looking for something like this, and i came across this page. It helpd me, but i had to fix your code, for it to work. I think that this is what you tried. You have to refference your objects by their "ID". Here is what I've done, and it works:

    HTML

    NAME
    PROFILE DETAILS
    NAME 2
    PROFILE DETAILS 2
    NAME 3
    PROFILE DETAILS 3

    CSS

    .name{
        float:left;
        margin:100px;
        border:1px solid black;
    }
    .tooltip{
        position:absolute;
        margin:5px;
        width:200px;
        height:50px;
        border:1px solid black;
        display:none;
    }
    

    JS

    function show (elem) {  
        elem.style.display="block";
    }
    function hide (elem) { 
        elem.style.display=""; 
    }
    

    http://jsfiddle.net/5qbP3/28/

提交回复
热议问题