How to make tooltip with pure javascript (onclick show/dismiss) [closed]

北城以北 提交于 2019-12-14 03:24:30

问题


I need to use some JS no JQuery plugins to make a simple tooltip.

When I click on image I want to display div with triangle corner bellow that image with some text inside.

I google and google and didn't find anything.

Simple click on image to show info and click on same image to dismiss it but can't figure out how to do this.


回答1:


If you're willing to use jquery, but not a plugin, then this can be done pretty simply.

http://jsfiddle.net/GQE4k/

var h = false;
$("#container").hover(function(){
    if (h == false){
        $("#popUp").fadeIn();
        $("#popUpText").fadeIn();
        h = true;
    }
},function(){
    if (h == true){
        $("#popUp").fadeOut();
        $("#popUpText").fadeOut(function(){h=false});
    }
});

For click instead of hover:

http://jsfiddle.net/GQE4k/1/

var h = false;
$("#container").click(function(){
    if (h == false){
        $("#popUp").fadeIn();
        $("#popUpText").fadeIn(function(){h = true;});
    }
    if (h == true){
        $("#popUp").fadeOut();
        $("#popUpText").fadeOut(function(){h=false});
    }
});


来源:https://stackoverflow.com/questions/20153882/how-to-make-tooltip-with-pure-javascript-onclick-show-dismiss

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!