简体   繁体   English

无法在Internet Explorer 10中使用JQuery更新Offset

[英]Cannot update Offset using JQuery in Internet Explorer 10

I'm trying to set an the offset of an element. 我正在尝试设置元素的偏移量。 The code works ok in Chrome but i can't get the offset to change in IE; 代码在Chrome中运行正常,但我无法在IE中获得更改的偏移量;

this.moveH = function (e) {

    if (this.target != null){
        console.log(this.target.offset())
        this.target.offset({
            left: e.pageX - this.target.outerWidth(true) / 2,
            top: e.pageY - this.target.outerHeight(true) / 2
        });
    }
    console.log(this.target.offset())
    e.preventDefault();
}

If i run in chrome the first console.log is different from the second. 如果我在chrome中运行,则第一个console.log与第二个不同。 If i run in IE it never changes. 如果我在IE中运行它永远不会改变。 Thank you 谢谢

Update 1 The offset function is the one from JQuery 更新1偏移函数是来自JQuery的函数

Update 2 Added HTML and CSS 更新2添加了HTML和CSS

*{
    margin:0px;
    left:0px;
    right:0px;
}
#applet {
    position: absolute;
    width: 700px;
    height: 520px;
    direction:ltr;
    text-align: center;
}
#puzzle{
    top:80px;
    left:20px;
    position:absolute;
}

.left-column{
    position:absolute;
    width:388px;
}

.left-puzzle{
    margin-top:10px;
    width:388px;
    background-image:url("../images/left_puzzle.png");
    height:83px;
}
.left-puzzle p{
    margin-right:194px;
}

.right-column{
    float:right;
    left:500px;
    width:182px;
    margin-right:10px;
}
.targets{
    left:206px;
    top:1px;
    width:194px;
    position:absolute;
}
.target{
    margin-top:10px;
    width:194px;
    height:83px;
}
.right-puzzle{
    margin-top:10px;
    width:182px;
    height:82px;
    background-image:url("../images/right_puzzle.png")
}

#bg{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

HTML HTML

<div id='applet'>
            <img id='bg' src='images/background.jpg' />
            <div id="puzzle">

                <div class="left-column">

                    <div class="left-puzzle">
                        <p>يبدأ خلف الشرج ولدى بعض الحبليات ذيل يوجد في مرحلة الجنين فقط.</p>
                    </div>

                    <div class="left-puzzle">
                        <p>يمتد بطول الظهر وهو مليء بالسائل عند الفقاريات ويطلق عليه اسم الحبل الشوكي .</p>
                    </div>

                    <div class="left-puzzle">
                        <p>تتطور إلى خياشيم أو إلى أجزاء أخرى من الجسم أثناء تطور الجنين .</p>
                    </div>

                    <div class="left-puzzle">
                        <p>قضيب صلب لكنه مرن يدعم الجسم وفي الفقاريات يحل محله عمود فقري .</p>
                    </div>
                </div>
                <div class="targets">
                    <div class="target drop" id="t1"></div>
                    <div class="target drop" id="t2"></div>
                    <div class="target drop" id="t3"></div>
                    <div class="target drop" id="t4"></div>
                </div>
                <div class="right-column">
                    <div id="d1" class="right-puzzle drag" data-target-id="t2">
                        <p>الحبل العصبي المجوف</p>
                    </div>
                    <div id="d2" class="right-puzzle drag" data-target-id="t1">
                        <p>الذيل</p>
                    </div>
                    <div id="d3" class="right-puzzle drag" data-target-id="t3">
                        <p>الجيوب البلعومية </p>
                    </div>
                    <div id="d4" class="right-puzzle drag" data-target-id="t4">
                        <p>الحبل الظهري</p>
                    </div>
                </div>
            </div>
        </div>

Try using native javascript instead. 尝试使用原生javascript代替。 Use obj.offsetLeft and obj.offsetTop. 使用obj.offsetLeft和obj.offsetTop。 It should work in IE as well. 它也应该在IE中工作。 Looks like a cross browser issue to me. 看起来像是一个跨浏览器问题。

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

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