FloatingTips在悬停时保持活动状态

时间:2013-06-17 10:46:52

标签: mootools tooltip

我正在为我的项目使用FloatingTip工具提示,我正在努力保持活跃状态​​,当光标在工具提示时不要关闭。
听到jsFiddle [ http://jsfiddle.net/SLvUz/3/ ][1] 例如:当鼠标悬停到工具提示并锚定让我看看!工具提示保持打开状态。

详情链接:https://github.com/lorenzos/FloatingTips

有任何想法或建议吗?感谢。

1 个答案:

答案 0 :(得分:3)

不幸的是,此插件目前没有这样的选项,但它有方法和事件,因此您可以使用它们来实现此行为。代码可能如下所示:

$$('#advanced a').each(function(elem){
    var instance = new FloatingTips(elem, {
        // example options
        content: function() { return $('htmlcontent'); },
        html: true,         // I want that content is interpreted as HTML
        center: false,      // I do not want to center the tooltip
        arrowOffset: 16,    // Arrow is a little more the the right
        offset: { x: -10 }, // Position offset {x, y}

        // override show/hide events
        showOn: null,
        hideOn: null
    });

    // customize tooltip behavior
    var delay = 100, timer;

    var tipHover = function() {
        clearTimeout(timer);
    }
    var tipLeave = function() {
        clearTimeout(timer);
        timer = setTimeout(function(){
            instance.hide(elem);    
        }, delay);
    }

    instance.addEvents({
        show: function(tip, elem){
            tip.addEvents({
                mouseover: tipHover,
                mouseout: tipLeave                    
            });
        },
        hide: function(tip, elem){
            tip.removeEvents({
                mouseover: tipHover,
                mouseout: tipLeave                    
            });   
        }
    });

    elem.addEvents({
        mouseover: function() {
            clearTimeout(timer);
            timer = setTimeout(function(){
                instance.show(elem);    
            }, delay);                
        },
        mouseout: function() {
            clearTimeout(timer);
            timer = setTimeout(function(){
                instance.hide(elem);    
            }, delay);  
        }
    });
});

点击此处查看更新的小提琴:http://jsfiddle.net/SLvUz/455/