Problem with jquery animations and Internet explorer 8

I worked a lot this evening trying to understand html positions and jquery animations. I made an HTML page as follows:

<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> 

Thus, the page shows flash animation with a diagonal movement to the left and right of the screen.

And it was perfect for me and works great in firefox, opera, safari, chome, but not in Internet explorer 8 !!, what can I do to fix this problem? = (

PS if I use the absolute position in both DIVs, the animation works in Internet Explorer, but unnecessary scrollbars are created.

thanks

+4
source share
1 answer

I see several things that can lead to various problems in your code example:

1. JavaScript

First of all, you almost never use any jQuery. Since you are already using jQuery, you can use it to the full and save a lot of headaches. For example, instead of implementing your own moveDIV () function, you can use:

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

almost exactly how you use .animate () in your code. You can also use offset () for this, which is better for you:

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

Read about .offset() , .css() and .animate() in jQuery API docs .

By the way, instead of using:

 setTimeout("anim1()",22000); 

better to use:

 setTimeout(anim1, 22000); 

He does the same, but more efficiently.

2. CSS

You can try experimenting with position: absolute or position: relative , where you have position: fixed .

3. HTML

You do not have a doctype, and IE may try to display your page in quirks mode. To use standards mode, add doctype at the very beginning of your HTML: <!doctype html>

In fact, IE8 might even use the IE7 rendering engine if it thinks it would be better for your site. If you want to make sure you always render the best rendering engine in IE, you should also add: <meta http-equiv="X-UA-Compatible" content="IE=Edge">

In addition, when you verify that your site is running IE8, you can also use the Google Chrome Frame plugin if available: <meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">

In general, the beginning of your HTML should look something like this:

 <!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 

This is just what I see in the code, which you can change. I don’t know if this is dealing with your problem, but even if it does not help you get rid of the need to deal with other problems later.

+7
source

Source: https://habr.com/ru/post/1342072/


All Articles