首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >FireFox中的Div位置不正确

FireFox中的Div位置不正确
EN

Stack Overflow用户
提问于 2012-11-10 05:06:54
回答 2查看 151关注 0票数 0

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

代码语言:javascript
复制
<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函数来显示工具提示:

代码语言:javascript
复制
    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("top", event.y - $('.facebookHoverDiv').height());调用中。

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-11-10 06:40:15

我想通了。以防其他人遇到这个问题。该问题是由使用event.xevent.y属性引起的。这些属性在Chrome中存在,但在其他浏览器中称为event.clientXevent.clientY。将属性更改为this修复了我的问题。

票数 2
EN

Stack Overflow用户

发布于 2012-11-10 05:17:35

设置一个单位

代码语言:javascript
复制
.css("left", (event.x - 65) + "px");

对top做同样的事情

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13316037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档