2

如何在不丢失测试文本且不克隆的情况下将方向从“n”更改为“w”?

$(".tipsy").live('mouseover',function() {
    $(this).tipsy({gravity: "n", html: true});
    $(this).tipsy("show");
});

$(".tipsy").live("click",function() {
    $('.tipsy').remove();
    $(this).tipsy({gravity: 'w', html: true});
    $(this).tipsy("show");
});

<div class="tipsy" title='<u>test link</u>'>TestTestTestTestTestTestTestTestTestTestTest</div>

这是一个小提琴:http: //jsfiddle.net/nQvmw/23/

4

1 回答 1

2

正如所见在 Tipsy 插件主页中,您可以传递一个返回方向的函数作为您的重力选项:

$(el).tipsy({gravity: function(){return Math.random()>.5 ? 'w' : 'n';}

基于此功能,您可以轻松地创建一个函数,为不同的鼠标操作(mouseenter、click...)返回不同的方向:

var flag = false;
function gravity(){
    return flag ? 'n' : 'w';
};

$(".tipsy")
    .live('mouseover',function(){
        flag = true;
        $(this).tipsy("show");
    })
    .live("click",function() {
        flag = false;
        $(this).tipsy("show");
    })
    .tipsy({
        gravity: gravity,
        html: true
    });

这是工作演示

于 2012-03-30T15:22:31.150 回答