jquery动画和Internet Explorer 8的问题

Leo*_*rdo 4 html javascript jquery animation

今天晚上我努力学习html位置和jquery动画,我做了一个HTML页面,如下所示:

<html>
<head>

<script src="jquery-1.5.1.min.js" type="text/javascript"></script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
    background-image: url(Cartoon_Landscape2.jpg);
}

</style>


<script type="text/javascript">
function moveDIV ( obj, x, y ) {
var element = document.getElementById(obj);
element.style.left=x;
element.style.top=y;
}

var t;

function anim1()
{
moveDIV("mariposa", screen.availWidth, screen.availHeight);
$("#mariposa").animate({left: '-84', top: '-58'}, 10000);

t=setTimeout("anim1()",22000);

//moveDIV("mariposa2", '-84', screen.availHeight);
//$("#mariposa2").animate({left: screen.availWidth, top: '-58'}, 10000);
}

function anim2()
{
moveDIV("mariposa2", '-84', screen.availHeight);
$("#mariposa2").animate({left: screen.availWidth, top: '-58'}, 10000);

t=setTimeout("anim2()",22000);

}

function callfunctions()
{
moveDIV("mariposa2", '-84', screen.availHeight);
anim1();
var b=setTimeout("anim2()",11000);
}
</script> 



</head>
<body  onLoad="javascript:callfunctions();"     >



<div id="mariposa" style="position:fixed; overflow: hidden;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" name="mariposa" width="84" height="58" align="top">
<param name=movie value="mariposa.swf">
<param name=wmode value=transparent>
<param name=quality value=high>
<embed src="mariposa.swf" width="84" type="application/x-shockwave-flash" height="58" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="transparent" align="top" name="mariposa">
</embed>
</object>
</div>

<div id="mariposa2" style="position:fixed; overflow: hidden;">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=4,0,0,0" name="mariposa2" width="-84" height="58" align="top">
<param name=movie value="mariposa2.swf">
<param name=wmode value=transparent>
<param name=quality value=high>
<embed src="mariposa2.swf" width="84" type="application/x-shockwave-flash" height="58" quality=high pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" wmode="transparent" align="top" name="mariposa2">
</embed>
</object>
</div>

</body>
</html>
Run Code Online (Sandbox Code Playgroud)

因此页面显示了一个从屏幕左侧和右侧进行对角线运动的flash动画.

并且非常适合我,并且在firefox,opera,safari,chome上工作得很好,但不适用于Internet Explorer 8 !!,我该怎么做才能解决这个问题?=(

PS如果我在两个DIV中使用绝对位置,动画可以在Internet Explorer上运行,但会创建不必要的滚动条.

谢谢

rsp*_*rsp 7

我看到几个可能导致示例代码中出现各种问题的事情:

1. JavaScript

首先,你几乎没有使用任何jQuery.由于您已经在使用jQuery,因此您可以将其全部使用,并为您节省很多麻烦.例如,您可以使用以下命令而不是实现自己的moveDIV()函数:

$("#id").css({left: 10, top: 10});
Run Code Online (Sandbox Code Playgroud)

几乎就是你在代码中使用.animate()的方式.您还可以使用offset()取决于哪种方式更适合您:

$("#id").offset({left: 10, top: 10});
Run Code Online (Sandbox Code Playgroud)

阅读.offset(),.css().animate()jQuery API文档中.

顺便说一句,而不是使用:

setTimeout("anim1()",22000);
Run Code Online (Sandbox Code Playgroud)

最好使用:

setTimeout(anim1, 22000);
Run Code Online (Sandbox Code Playgroud)

它做同样的事情,但效率更高.

2. CSS

您可以尝试尝试position: absoluteposition: relative在哪里进行实验position: fixed.

3. HTML

您没有doctype,IE可能会尝试以怪癖模式呈现您的页面.要使用标准模式,请在HTML的最开头添加doctype:<!doctype html>

实际上IE8甚至可以使用IE7渲染引擎,如果它认为它对你的网站更好.如果你想确保你总是由IE中最好的渲染引擎渲染,你还应该添加:<meta http-equiv="X-UA-Compatible" content="IE=Edge">

此外,当您确保您的网站适用于IE8时,您还可以使用Google Chrome Frame插件(如果可用):<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">

总而言之,HTML的开头看起来应该是这样的

<!doctype html>
<html lang="en-us">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1" >
  ... and the rest of your HTML
Run Code Online (Sandbox Code Playgroud)

这些只是我在您的代码中看到的主要内容,您可能会考虑更改.我不知道这样做是否解决了你的问题,但即使它没有,也可能让你免于以后再处理其他问题.