简体   繁体   English

IE8,jQuery UI Tooltip在Internet Explorer 8中立即关闭

[英]IE8, jQuery UI Tooltip closes immediately in Internet Explorer 8

The setup 设置

We have a jQuery UI tooltip that is displayed via a mouseenter event attached to the <div class="fieldset"> (.fieldset) element inside the form element. 我们有一个通过一个显示一个jQuery UI工具提示mouseenter附加到事件<div class="fieldset"> (.fieldset)形式元素中的元素。 When the mouse leaves the div, the tooltip should disappear. 当鼠标离开div时,工具提示应消失。

The problem 问题

In IE8, and only IE8, the tooltip disappears immediately when you hover over the area of the .fieldset element. 在IE8中(只有IE8中),当您将鼠标悬停在.fieldset元素的区域上时,工具提示会立即消失。 IE8 behaves as if the child elements are not actually decedents of the parent element, or as if the tooltip is using the mouseover and mouseout events. IE8的行为就像子元素实际上不是父元素的后代一样,或者工具提示使用的是mouseovermouseout事件。 However, we are using the mouseenter and mouseleave events for this tooltip. 但是,我们在此工具提示中使用mouseentermouseleave事件。

I have tried giving the .fieldset element a solid background. 我尝试为.fieldset元素提供扎实的背景。 I also tried a transparent image. 我还尝试了透明图像。 I've checked the z-index of the child elements to make sure there weren't different. 我检查了子元素的z-index ,以确保它们没有什么不同。 Nothing I do seems to work. 我似乎无济于事。

I need the tooltip to stay displayed while the mouse hovers over the .fieldset element and any of its children. 当鼠标悬停在.fieldset元素及其.fieldset元素上时,我需要工具提示保持显示状态。

Code

HTML: HTML:

<form class="form centerBH" id="form" style="display: block; zoom: 1;">

    <div class="fieldset">

        <h2 class="legend">Autogenerated Image Links</h2>

        <div id="image" class="panebox" >
        <div class="ui-widget"> 
            <ul>

            </ul>
        </div>      
        </div>

    </div>
</form>

CSS: CSS:

.form {

    width: 50em;

    /* correct margin collapse in IE */
    overflow: auto;
}

/* ensure all form elements will fade in and out */
form * {

    filter: inherit;

}

.panebox {

    background-color: #F7F7F7;

    border-color: #B7B9BD;
    border-radius: 10px;
    border-style: solid;
    border-width: 1px;

    box-shadow:  0px 1px 0px 0px rgba(255,255,255,.7), 0px 1px 2px 0px rgba(0,0,0,.1);

    margin: 7px;
    padding: 14px;

    position: relative;

    overflow: hidden;
}

JavaScript: JavaScript:

Again, I'm using jQuery UI tooltip, which automagically binds to any elements that have a title attribute defined. 同样,我使用的是jQuery UI工具提示,它自动绑定到定义了title属性的任何元素。 However, I have tried explicitly attaching the mouseenter and mouseleave events to the .fieldset div, to display and hide the tooltip, but I still get the same behavior. 不过,我已经试过了明确安装mouseentermouseleave事件到.fieldset DIV,显示和隐藏工具提示,但我仍然得到同样的行为。

Here is how I setup the tooltip: 这是我设置工具提示的方式:

this.fieldsetTooltip=this.$(".fieldset").tooltip({

            content: 'Click an image link to open that image.',
            disabled: true,
            items: ".fieldset",
            position: {
                my:"left+20 top+25", 
                at:"right top",
                collision: "none",
                using: function( position, feedback ) {

                    //console.log(feedback.target.width);

                    $( this ).css( position );

                    $( "<div>" )
                        .addClass( "arrow" )
                        .addClass( feedback.vertical )
                        .addClass( feedback.horizontal )
                        .appendTo( this );
                }

            }
        });          

Here is how I manually open and close the tooltip: 这是我手动打开和关闭工具提示的方法:

this.$el.on("mouseenter",'.fieldset',function(e){

        console.log("Mouse entering .fieldset");
        _this.fieldsetTooltip.tooltip("open");


});


this.$el.on("mouseleave",'.fieldset',function(e){

        console.log("Mouse leaving .fieldset");
        _this.fieldsetTooltip.tooltip("close");


});

We also trigger a custom resize event when the window object triggers it's resize event. 当窗口对象触发其调整大小事件时,我们还将触发一个自定义调整大小事件。

// close tooltip when user resizes the window
this.listenTo(AppReg.events,"context:resized",function() {

        _this.fieldsetTooltip.tooltip("close");
}); 

Update Based on the console log from the above events, the mouseenter and mouseleave events are firing as they should. 更新根据上述事件的控制台日志, mouseentermouseleave事件将按mouseleave触发。 However, I think the jQuery UI tooltip is binding a different event to the element (maybe a 'mouseout'?), which is causing it to close automatically. 但是,我认为jQuery UI工具提示正在将一个不同的事件绑定到该元素(可能是“ mouseout”?),这导致它自动关闭。

Anybody know how this can be stopped? 有人知道如何可以停止吗?

The culprit to the problem is the way that IE8 handles the resize event. 问题的根源在于IE8处理调整大小事件的方式。 I was attaching a resize event handler on the window object, using $(window).resize() . 我正在使用$(window).resize()在窗口对象上附加一个调整大小事件处理程序。 For some reason, IE8 was firing the resize event whenever the tooltip was displayed. 由于某种原因,每当显示工具提示时,IE8都会触发调整大小事件。

I used the solution from this post: window.resize event firing in Internet Explorer 我使用了这篇文章中的解决方案: Internet Explorer中触发window.resize事件

Basically, you have to check to make sure the window's dimensions actually changed before firing the event. 基本上,您必须在触发事件之前检查以确保窗口的尺寸实际发生了变化。

I had a bit similar issue on Nokia Lumia 520 Internet Explorer 11 (IE 11). 我在诺基亚Lumia 520 Internet Explorer 11(IE 11)上遇到了类似的问题。 I added additional code for showing tooltip: 我添加了用于显示工具提示的其他代码:

$(".has_tooltip").tooltip();
if (/Lumia/.test(navigator.userAgent) && getInternetExplorerVersion() == 11)
        {
                $(".has_tooltip").click(function(){
                    $(this).tooltip("open");
                })
        }

So, in my case, $(this).tooltip("open"); 因此,就我而言, $(this).tooltip("open"); does the trick. 绝招。

*in my mobile app tooltip is appearing when element is clicked. *单击元素时,将在我的移动应用程序中显示工具提示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM