2012-09-24 50 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()函數。