如何将方向从“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>
这是一个 fiddle :http://jsfiddle.net/nQvmw/23/
最佳答案
如图所示在醉酒插件主页中,您可以传递一个返回方向的函数作为重力选项:
$(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
});
这是working demo
关于jQuery 醉酒 : Simple Overwriting Solution?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9880728/