JQuery: animate() doesn't work as expected in IE

后端 未结 8 967
广开言路
广开言路 2021-01-06 02:17

I\'m getting crazy with this IE 7...

==> hhttp://neu.emergent-innovation.com/

Why does following function not work in IE 7, but perfectly with Firefox? Is th

8条回答
  •  天命终不由人
    2021-01-06 03:12

    I came across a similar problem with the animate function and was surprised when it was showing the error coming from the core jQuery library. However jQuery is fine, its IE you need to cater for.

    When animating any attribute of an element in IE, you need to make sure that in your CSS there is a starting point for the attribute you are going to alter. This also applies to Safari.

    As an example, moving a div continually to the left,

    JQuery:

    var re = /px/;
    var currentLeft = $("#mydiv").css('left').replace(re,'') - 0;
    $("#mydiv").css('left',(currentLeft-20)+'px');
    

    CSS:

    #mydiv { position: absolute;    top: 0;    left: 0; }
    

    If you DO NOT put in a left & top starting position IE will eventually throw an error.

    Hope this helps

提交回复
热议问题