jquery - Div 未在 FireFox 中正确定位

标签 jquery css firefox html

我在定位 div 时遇到问题。这是 div:

<div class="facebookHoverDiv" style="position: absolute; top: 0; left: 0; z-index: 15000; display: none">
<div class="calendar-hover-top"></div>
<div class="calendar-hover-middle">
    <div class="post-image"></div>
    <div class="facebook-icon">Facebook</div>
    <div class="post-content"><span id="facebook-text">content</span>
        <div class="post-date">This will be the date.</div>
    </div>
</div>
<div class="calendar-hover-bottom"></div>
</div>

<div class="twitterHoverDiv" style="position: absolute; top: 0; left: 0; z-index: 15000; display: none">
<div class="calendar-hover-top"></div>
<div class="calendar-hover-middle">
    <div class="twitter-icon">Twitter</div>
    <div class="post-content"><span id="twitter-text">content</span>
        <div class="post-date">This will be the date.</div>
    </div>
</div>
<div class="calendar-hover-bottom"></div>
</div>

我正在使用以下 jQuery 函数来显示工具提示:

    function ShowToolTip(event, postType, postMessage, scheduleDate, customPostId, postId) {
        if (postType == 'Twitter') {
            $('.twitterHoverDiv .post-content #twitter-text').text(postMessage);
            $('.twitterHoverDiv .post-content .post-date').text(scheduleDate);
            $('.twitterHoverDiv').css("left", event.x - 65);
            $('.twitterHoverDiv').css("top", event.y - $('.twitterHoverDiv').height());


            $('.facebookHoverDiv').hide();
            $('.twitterHoverDiv').show();
        } else {
            $('.facebookHoverDiv .post-content #facebook-text').text(postMessage);
            var url = "http://host.mmm.dev.webedge.mcmurry.com/Media/Image.ashx?articleid=" + postId + "&custompostid=" + customPostId;
            //url = url.replace("undefined", "0");
            $('.facebookHoverDiv .post-image').css("background-image", "url('" + url + "')");
            $('.facebookHoverDiv .post-image').css("background-size", "100%");
            $('.facebookHoverDiv .post-content .post-date').text(scheduleDate);
            $('.facebookHoverDiv').css("left", event.x - 65);
            $('.facebookHoverDiv').css("top", event.y - $('.facebookHoverDiv').height());


            $('.twitterHoverDiv').hide();
            $('.facebookHoverDiv').show();
        }
    }

如果我在 Google Chrome 中运行它,它会完美运行。但是,如果我在 FireFox 中运行它,工具提示会显示在屏幕的左上角。问题似乎出在 $('.facebookHoverDiv').css("left", event.x - 65);$('.facebookHoverDiv').css( “顶部”,event.y - $('.facebookHoverDiv').height()); 调用。

我需要为 FireFox 做一些特定的事情吗?

最佳答案

我想通了。以防万一其他人遇到这个问题。该问题是由使用 event.xevent.y 属性引起的。这些属性存在于 Chrome 中,但在其他浏览器中它们被称为 event.clientXevent.clientY。将属性更改为此解决了我的问题。

关于jquery - Div 未在 FireFox 中正确定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13316037/

相关文章:

javascript - 通过 javascript 或 jquery 将 anchor 的状态更改为事件状态

perl - Mechanize::Firefox 卡住了

jquery焦点回调

jQuery 选项卡 - 在 ajax 加载期间在容器 div 中显示指示器

javascript - 是否可以在页面正文中加载 Jquery

css - 如何为阿拉伯语网站使用 Dejavu 字体?

html - 我该怎么做才能单击 html 复选框并更改 html 输入的内容?

javascript - 有什么方法可以从他们制作的 Bootstrap 模板(带有 HTML)下载并在官方网站上作为示例显示

jquery - 引用错误: g is not defined error in Firefox 26. 0

javascript - 我想关闭通过后端C#进程打开的firefox浏览器