【问题标题】:jQuery animate w/marginTop not working in IE9带有marginTop的jQuery动画在IE9中不起作用
【发布时间】:2012-06-19 03:12:41
【问题描述】:

我在这里运行了一个测试:http://raglefant.com/test.php 我在标题中有这个 jQuery:

$(document).ready(function() {
    $('#hideable_header').stop().delay(2000).animate(
            {marginTop: '-=290'}
        ,1000,function() {
    });

    $('#hideable_header').click(function() {
        var position = parseInt($("#hideable_header").css("margin-top"),10);
        console.log('Position: ' + position);
        if (position == 0)
        {
            $('#hideable_header').stop().animate(
                    {marginTop: '-=290'}
                ,1000,function() {
            });
        }
        else
        {
            $('#hideable_header').stop().animate(
                    {marginTop: '+=290'}
                ,1000,function() {
            });
        }
    });
});

这是 div:

<div id="hideable_header" style="position:fixed; top: 0; left: 0; width: 100%; height: 300px; background: #000; z-index:9999;"></div>

这在 Chrome 中运行良好,但在 IE9 中不行。如果我单击 DIV,它应该更改 margintop 以隐藏或显示 DIV,但在 IE9 中没有任何反应。 如果我在 IE9 中打开 devtools,一切正常,没有出现任何错误。但是当我关闭页面并再次打开它时,它仍然失败。

有什么想法吗?

【问题讨论】:

    标签: jquery internet-explorer-9


    【解决方案1】:

    在 IE9 中为我工作,但在 IE8 中不是你所期望的。在 IE8 中,初始位置是 NaN,所以我建议在内联样式中将 margin-top 设置为 0。

    【讨论】:

      猜你喜欢
      • 2012-08-09
      • 2017-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多