1

我在一家新公司开始工作,他们给了我一些在 IE 中崩溃的 jQuery。由于某种原因,仅在 Internet Explorer 中向上或向下滚动页面后,工具提示的位置不会重新计算。文件中有很多内容,但这是我认为与帮助最相关的部分:

reposition: function (target, tip, classes) {
                var width, nub, nubHeight, nubWidth, row, objPos;
                tip.css('visibility', 'hidden').show();
                width = target.data('width');
                nub = tip.children('.nub');
                nubHeight = nub.outerHeight();
                nubWidth = nub.outerWidth();
                objPos = function (obj, top, right, bottom, left, width) {
                    return obj.css({
                        'top': top,
                        'bottom': bottom,
                        'left': left,
                        'right': right,
                        'width': (width) ? width : 'auto'
                    }).end()
                };

                objPos(tip, (target.offset().top - tip.outerHeight() - nubHeight), 'auto', 'auto', target.offset().left, width);
                objPos(nub, 'auto', 'auto', -nubHeight, 'auto');  


                 <!--Some code here only if the window is less than 767px-->


   show: function ($target) {
            var $tip = methods.getTip($target);
            methods.reposition($target, $tip, $target.attr('class'));
            $tip.fadeIn(150)
        },

小块指的是工具提示底部的小尾巴,所以它看起来像一个引用气泡。

更新 我为 scrollTop 创建了一个警报,它在 IE 中一直显示为 0,而其他浏览器会正确重新计算。所以多亏了这篇文章,我才能重新计算它。现在我的代码看起来像这样(用星号标记的更改):

 reposition: function (target, tip, classes) {
                var width, nub, nubHeight, nubWidth, row, objPos;
                tip.css('visibility', 'hidden').show();
                width = target.data('width');
                nub = tip.children('.nub');
                nubHeight = nub.outerHeight();
                nubWidth = nub.outerWidth();
            **pageTop = (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;**          
                objPos = function (obj, top, right, bottom, left, width) {
                    return obj.css({
                        'top': top,
                        'bottom': bottom,
                        'left': left,
                        'right': right,
                        'width': (width) ? width : 'auto'
                    }).end()
                };

                **objPos(tip, (pageTop + (target.offset().top - tip.outerHeight() - nubHeight)), 'auto', 'auto', target.offset().left, width);**
                objPos(nub, 'auto', 'auto', -nubHeight, 'auto');

所以它在 IE(耶)中工作,但现在它在 Firefox 和 Chrome 中关闭。我越来越近了。我能感觉到。如果有人在这一点上可以帮助我,我将不胜感激,否则我会在时间允许的情况下进行。

更新 2:我现在更新了我的 pageTop 变量:

 pageTop = $('html').scrollTop();

这适用于 IE8 和 Chrome,但可惜的是,Firefox 不喜欢它。我也试过

 pageTop = $('body,html').scrollTop();

但它也没有任何作用,而且它更长,所以我把它拿出来了。

战斗还在继续。

4

0 回答 0