2012-09-24 58 views
5

我有jQuery的问题,点击功能。我想编辑一个来自“http://gdakram.github.com/JQuery-Tooltip-Plugin”的语音气泡插件。在这里你可以看到,如果你将鼠标悬停在按钮上,它会打开一个讲话泡泡。我想要点击这个功能,而不是鼠标悬停。 我的问题是,这个脚本是对我来说太复杂......这是从网站上一个部分(JS-数据):两个语音点击活动气泡

(function($) { 

$.fn.tooltip = function(settings) { 
// Configuration setup 
config = { 
'dialog_content_selector' : 'div.tooltip_description', 
'animation_distance' : 50, 
'opacity' : 0.85,*/ 
'arrow_left_offset' : 70, 
'arrow_top_offset' : 50, 
'arrow_height' : 20, 
'arrow_width' : 20, 
'animation_duration_ms' : 300, 
**'event_in':'click',** 
'hover_delay' : 0, 
**'event_out': 'click',** 
}; 

事件中和事件出来没有一起工作...任何想法,有什么我可不可以做?

回答

0

在这一点,他们是写代码来显示,并使用鼠标和鼠标了 因此该点击不能正常工作,请尝试用这种

click for tooltip show 
mousemove for tooltip hide 

(function($) { 

    $.fn.tooltip = function(settings) { 
    // Configuration setup 
    config = { 
    'dialog_content_selector' : 'div.tooltip_description', 
    'animation_distance' : 50, 
    'opacity' : 0.85,*/ 
    'arrow_left_offset' : 70, 
    'arrow_top_offset' : 50, 
    'arrow_height' : 20, 
    'arrow_width' : 20, 
    'animation_duration_ms' : 300, 
    'event_in':'click', 
    'event_out':'mousemove' 
    }; 

event_out可能'mousemove'或“mouseleave'

隐藏工具提示
+0

感谢您的回答!这是可能的,但如果我想点击对话框中的超链接呢?所以点击是不可能的,因为mouseleave或类似的东西。任何(其他)想法? – Mikey

+0

如果您希望泡泡上的超链接表示您何时会隐藏泡泡? – muthu

+0

然后改变像“event_in”事件:“鼠标悬停”,“event_out”:“点击” – muthu

0

»‘event_in’:‘鼠标悬停’,‘event_out’:‘点击’«看起来很漂亮,但并不完美......它出现之前,我可以用click事件...这是一个有点关闭它......‘丑’......抱歉情况。

0
if (settings) $.extend(config, settings); 

    /** 
     * Apply interaction to all the matching elements 
     **/ 
    this.each(function() { 
     var hoverTimer; 
     $(this).bind(config.event_in,function(){ 
     _hide(this); 
     var ele = this; 
     hoverTimer = setTimeout(function() { _show(ele); }, config.hover_delay) 
     }) 
     .bind(config.event_out,function(){ 
     clearTimeout(hoverTimer); 
     _hide(this); 
     }) 
    }); 
1

这是粗糙的,但应该工作 - 建立自己的“切换”就像方法:

config = { 
     'dialog_content_selector' : 'div.tooltip_description', 
     'animation_distance' : 50, 
     'opacity' : 0.85, 
     'arrow_left_offset' : 70, 
     'arrow_top_offset' : 50, 
     'arrow_height' : 20, 
     'arrow_width' : 20, 
     'animation_duration_ms' : 300, 
     '_event_' : 'click' 

     //'event_in':'mouseover', 
     //'event_out':'mouseout', 
     //'hover_delay' : 0 
    }; 

    if (settings) $.extend(config, settings); 

/** 
    * Apply interaction to all the matching elements 
    **/ 

this.each(function() { 

    toggleTip(this); 

}); 

/** 
    * Positions the dialog box based on the target 
    * element's location 
    **/ 

function toggleTip(tip) { 

    var count = 1; 

    $(tip).bind(config._event_, function(e){ 

     e.stopPropagation(); 

     _hide(tip); 

      count++ % 2 ? _show(tip) : _hide(tip); 

    }); 

    }; 

为了使这是真正有效的,你就需要重新考虑_show()和_hide()函数。