jQuery 醉酒 : Simple Overwriting Solution?

标签 jquery click mouseover tipsy

如何将方向从“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/

相关文章:

javascript - Jquery - 背景淡入淡出。

javascript - Codemirror:抓取标题值到输入[type=text]

jquery - Bootstrap 图标不可见

javascript - 为什么这个 jQuery 选择器表达式中的空格是相关的

javascript - 单击页面上任意位置时隐藏元素,单击其他元素时显示该元素

javascript - HtmlUnit按钮点击不提交

javascript - 使用 jquery 从 HTML 生成多维数组

javascript - 单击事件不会在第一次加载页面时触发

html - 鼠标悬停在 HTML 函数中以弹出或放大图片

javascript - 悬停时更改img标签内容