jquery - 具有多个显示事件的 qTip2 不起作用

标签 jquery qtip2

当我指定多个事件时,qTip2 仅在单击时起作用。 Mouseenter 或 focus 单独工作正常,但我想确保它适用于所有事件,以防移动设备上没有 mouseenter 事件。

$('span#message').qtip({
    content: {
        text: 'some text'
    },
    show: {
        event: 'click mouseenter focus'
    },
    hide: {
        event: 'click mouseleave blur'
    }
});

最佳答案

我遇到了同样的问题,我可以通过替换 jquery.qtip.js 中的以下代码来修复它:

PROTOTYPE._bindEvents = function(showEvents, hideEvents, showTargets, hideTargets, showCallback, hideCallback) {
    // Get tasrgets that lye within both
    var similarTargets = showTargets.filter( hideTargets ).add( hideTargets.filter(showTargets) ),
        toggleEvents = [];

    // If hide and show targets are the same...
    if(similarTargets.length) {

        // Filter identical show/hide events
        $.each(hideEvents, function(i, type) {
            var showIndex = $.inArray(type, showEvents);

            // Both events are identical, remove from both hide and show events
            // and append to toggleEvents
            showIndex > -1 && toggleEvents.push( showEvents.splice( showIndex, 1 )[0] );
        });

        // Toggle events are special case of identical show/hide events, which happen in sequence
        if(toggleEvents.length) {
            // Bind toggle events to the similar targets
            this._bind(similarTargets, toggleEvents, function(event) {
                var state = this.rendered ? this.tooltip[0].offsetWidth > 0 : false;
                (state ? hideCallback : showCallback).call(this, event);
            });

            // Remove the similar targets from the regular show/hide bindings
            showTargets = showTargets.not(similarTargets);
            hideTargets = hideTargets.not(similarTargets);
        }
    }

    // Apply show/hide/toggle events
    this._bind(showTargets, showEvents, showCallback);
    this._bind(hideTargets, hideEvents, hideCallback);
};

致:

PROTOTYPE._bindEvents = function(showEvents, hideEvents, showTargets, hideTargets, showCallback, hideCallback) {
    // Get tasrgets that lye within both
    var similarTargets = showTargets.filter( hideTargets ).add( hideTargets.filter(showTargets) ),
        toggleEvents = [];

    // If hide and show targets are the same...
    if(similarTargets.length) {

        // Filter identical show/hide events
        $.each(hideEvents, function(i, type) {
            var showIndex = $.inArray(type, showEvents);

            // Both events are identical, remove from both hide and show events
            // and append to toggleEvents
            showIndex > -1 && toggleEvents.push(type);
        });
        showEvents = showEvents.filter((el) => !toggleEvents.includes(el));
        hideEvents = hideEvents.filter((el) => !toggleEvents.includes(el));

        // Toggle events are special case of identical show/hide events, which happen in sequence
        if(toggleEvents.length) {
            // Bind toggle events to the similar targets
            this._bind(similarTargets, toggleEvents, function(event) {
                var state = this.rendered ? this.tooltip[0].offsetWidth > 0 : false;
                (state ? hideCallback : showCallback).call(this, event);
            });
        }
    }

    // Apply show/hide/toggle events
    this._bind(showTargets, showEvents, showCallback);
    this._bind(hideTargets, hideEvents, hideCallback);
};

关于jquery - 具有多个显示事件的 qTip2 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30940491/

相关文章:

jquery - 使用 jquery 选择器和正则表达式查找元素

jquery - 一起使用 jQuery Mobile 和 bootstrap 时页脚无法正常工作

javascript - 简单的?? onClick qTip 一些链接但不是全部

c# - 工具提示内容稍微不够宽

javascript - qTip2 中的 Ajax 表单

javascript - 使用 jQuery 解析 XML 并填充文本字段

javascript - 如何使用 jquery 中的数组或 json 中的动态数据填充多个 div

javascript - CSS/Jquery 在后台淡入淡出

jquery - 无法在 qtip 中使用 "style option"应用样式

jquery - 将 qTip2 方向设置为从右到左 (RTL)