【问题标题】:jQuery selector mouseover <select> stops working when I over an <option>当我在 <option> 上方时,jQuery 选择器 mouseover <select> 停止工作
【发布时间】:2011-09-01 10:17:45
【问题描述】:

我写了一个jQuery tooltip plugin 是:

 (function ($) {
    $.fn.meliaTooltip = function (options) {
        var defaults = {
            tooltip: '.miTooltip',
            tiempo_espera: 0,
            seguir_raton: true,
            ajuste_top: 0,
            ajuste_left: 0,
            fade_time: 300,
            bind_mode: 'click'
        };

        var opts = $.extend(defaults, options);

        $(this).each(function() {
            $(this).bind(opts.bind_mode,function(e) {
               // alert('has hecho '+opts.bind_mode+' en '+$(this).attr('id'));
                /*Guardamos el selector del disparador y de tooltip en una variable*/
                var disp = $(this);
                
                var tip = disp.next(opts.tooltip);
                var tip_text = tip.html();
                
                var new_content = '<span class="melia_tooltip_left"></span ><span class="melia_tooltip_contenido">' + tip_text + '</span ><span class="melia_tooltip_right"></span ><span class="melia_tooltip_bottom"></span >';
                tip.html(new_content);
                if (typeof t != 'undefined') {
                    /*reiniciamos tiempo_espera*/
                    clearTimeout(t);
                }
                //alert('has hecho '+opts.bind_mode+' en '+disp.attr('id')+'y ahora vamos a mostrar'+tip_text+'que esta en '+tip.attr('class'));
                $(tip).css({
                        //colocamos el tooltip según el ratón y el tamaño del tooltip
                        left: e.clientX - ($(tip).width() / 2) + opts.ajuste_left + 'px',
                        top: e.clientY - $(tip).height() * 3 / 2 + opts.ajuste_top + 'px'
                }).fadeIn(opts.fade_time);
                //alert(e.clientX - ($(tip).width() / 2) + opts.ajuste_left);
                //alert(e.clientY - $(tip).height() * 3 / 2 + opts.ajuste_top);
                
                
            });

            $(this).bind('mousemove', function(e) {
                if (opts.seguir_raton) {
                    var disp = $(this);
                    var tip = $(this).next(opts.tooltip);
                    $(tip).css({
                            /*Pues recolocamos el tooltip*/
                            left: e.clientX - ($(tip).width() / 2) + opts.ajuste_left + 'px',
                            top: e.clientY - $(tip).height() * 3 / 2 + opts.ajuste_top + 'px'
                        });
                }
            });

            $(this).mouseout(function() {
                /*añadimos tiempo_espera por si el usuario se sale sin querer*/
                t = setTimeout("$('" + opts.tooltip + "').fadeOut(" + opts.fade_time + ")", opts.tiempo_espera);
            });
        });
    };
})(jQuery);

$('select#id).meliaTooltip({}) 可以正常工作,但是当我将鼠标悬停在其中一个选项上时,工具提示会淡出,如何为孩子保留选择器?

即使我将其应用于另一种标签,例如:

<div id="selector"><div><div>Still work here</div></div>

【问题讨论】:

    标签: javascript jquery jquery-selectors


    【解决方案1】:

    使用mouseentermouseleave 事件而不是mousemove

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多