2012-04-03 17 views
0

Ich habe ein Problem mit IE8 + jQuery.css ('top') -Funktion.jQuery.css ('top') und IE8

1) Ich habe ein DIV mit 100px Höhe und 600px Breite. Ich habe ein anderes DIV innerhalb der ersten mit style = "top: 50%", also sollte es in top = 50px platziert werden.

2) Alle Browser zeigen es korrekt an. ABER, später muss ich jQuery verwenden, um die Position des Elements zu finden und hier kommt das Problem mit IE8:

$ ('# txt'). Css ('top') gibt mir nicht 50px ABER 300px !! !!! Das ist nicht korrekt. Auch habe ich gemerkt, dass es immer den Wert von 0,5 * BREITE des Elternteils DIV zurückgibt !! Es macht mich verrückt! wie könnte es sein?

hier ist der Code Beispiel:

<!DOCTYPE HTML> 
<html> 
<head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
    <title>demo</title> 

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script> 
    <script type="text/javascript">    
     function onLoadTest(){ 
      alert("document.getElementById('txt').style.top="+document.getElementById('txt').style.top+"\n$(#txt).css('top')="+$('#txt').css('top')); 
     } 
    </script> 

</head> 
<body onload="onLoadTest()" style="padding: 0px; margin: 0px; width:100%; height:100%">    
    <div id="box" style="width:600px; height:100px; position:absolute; padding:0px; margin:0px; border: solid 1px"> 
     <div id="txt" style="top:50%; position:relative; padding:0px; margin:0px;border: solid 1px"> 
      im in the position top=50% (which is 50px), plz compare to alert box data 
     </div>   
    </div> 
</body> 
</html> 

Antwort

0

Hier ist meine fiddle. Versuchen Sie es mit Offset(). IE wird manchmal komisch mit absolut. Mit Offset ist mit dem Boarder auf Ihre Eltern erhalten Sie 51, so nahm ich die Grenze von der Mutter

+0

Es funktioniert !!! :) Danke! :) – Stan