gpt4 book ai didi

javascript - jquery 动画和 Internet Explorer 8 的问题

转载 作者:搜寻专家 更新时间:2023-11-01 05:26:21 24 4
gpt4 key购买 nike

今天晚上我非常努力地试图理解 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>

因此页面从屏幕的左侧和右侧显示一个对 Angular 线运动的 flash 动画。

对我来说非常完美,在 firefox、opera、safari、chome 上运行良好,但在 internet explorer 8 上运行不佳!!,我该怎么做才能解决这个问题? =(

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

谢谢

最佳答案

我在您的示例代码中看到一些可能导致各种问题的事情:

1。 JavaScript

首先,您几乎没有使用任何 jQuery。既然您已经在使用 jQuery,那么您不妨充分利用它,从而避免很多麻烦。例如,除了实现您自己的 moveDIV() 函数,您还可以使用:

$("#id").css({left: 10, top: 10});

几乎完全符合您在代码中使用 .animate() 的方式。您还可以为此使用 offset() ,具体取决于什么对您更好:

$("#id").offset({left: 10, top: 10});

了解 .offset() , .css() .animate() jQuery API docs .

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

setTimeout("anim1()",22000);

最好用:

setTimeout(anim1, 22000);

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

2。 CSS

您可以尝试使用 position: absolute 进行试验或 position: relative你在哪里position: fixed .

3。 HTML

您没有文档类型,IE 可能会尝试以怪癖模式呈现您的页面。要使用标准模式,请在 HTML 的最开头添加文档类型:<!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

这些只是我在您的代码中看到的您可能考虑更改的主要内容。我不知道这样做是否能解决您的问题,但即使不能解决,您以后也不必再处理其他问题。

关于javascript - jquery 动画和 Internet Explorer 8 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5176474/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com