jQueryUI tooltip Widget to show tooltip on Click

前端 未结 7 2065
自闭症患者
自闭症患者 2020-12-10 13:48

How the new jQueryUI\'s tooltip widget can be modified to open the tooltip on click event on certain element\'s on document, while the others are still showing their tootip

7条回答
  •  我在风中等你
    2020-12-10 14:12

    This code creates a tooltip that stays open until you click outside the tooltip. It works even after you dismiss the tooltip. It's an elaboration of Mladen Adamovic's answer.

    Fiddle: http://jsfiddle.net/c6wa4un8/57/

    Code:

    var id = "#tt";
    var $elem = $(id);
    
    $elem.on("mouseenter", function (e) {
        e.stopImmediatePropagation();
    });
    
    $elem.tooltip({ items: id, content: "Displaying on click"});
    
    $elem.on("click", function (e) {
        $elem.tooltip("open");
    });
    
    
    $elem.on("mouseleave", function (e) {
        e.stopImmediatePropagation();
    });
    
    
    $(document).mouseup(function (e) {
        var container = $(".ui-tooltip");
        if (! container.is(e.target) && 
            container.has(e.target).length === 0)
        {
            $elem.tooltip("close");
        }
    });
    

提交回复
热议问题