views:

47

answers:

2

Hi guys. I am trying to animate a div when the user click the button. Each button will move a div to a different amount of pixels. My code works in firefox and chrome but not IE8 (I only test it in IE8 so far). I appreciate it if someone could help me about it.

my jquery

$(document).ready(function(){

function breakline(position) {
     $('#breakline').animate({  //this code won't work...
    top:position},'slow'); 

    $('#breakline').hide(); //this code would work. I put it here just for testing                
                                //purpose
    };


$('#project a').click(function(){
breakline(256);
});

$('#code a').click(function(){
breakline(200);
});

$('#skill a').click(function(){
breakline(236);
});

$('#about a').click(function(){
breakline(190);
});

$('#contact a').click(function(){
breakline(200);
});

});/* ready */

my html

<body>

<div id="main">  
   <div id="menu-wrapper">
     <ul id="menu">
    <li id="project"><a href="#"></a></li>
    <li id="code"><a href="#"></a></li> 
    <li id="skill"><a href="#"></a></li>
    <li id="about"><a href="#"></a></li>
    <li id="contact"><a href="#"></a></li>
     </ul>
<div id='breakline'> </div>
</div> <!-- menu wrapper -->
</body>
</HTML>

part of CSS

#breakline
{
width:580px;
height:100px;
background-image:url('breakline.png');
background-repeat:no-repeat;
float:left;
border:1px solid black;
}
+1  A: 

I had to add some positioning to the breakline class to get it to animate instead of just hiding.

add position: relative to the #breakline css class

Simon Hazelton
Placing the function outside `.ready()` wouldn't change anything.
patrick dw
thanks for the reply, but still not working...:(
Jerry
Thanks a lot.... +1
Jerry
+2  A: 

If you add position:relative to your style it works in IE8.

http://jsfiddle.net/NPxt6/1/

#breakline
{
    width:580px;
    height:100px;
    background-image:url('breakline.png');
    background-repeat:no-repeat;
    float:left;
    border:1px solid black;
    position:relative;
}​
patrick dw
Thanks patrick. .hide() is for testing purpose, I won't use it in my real site. I copy and paste your second code, still not working for me...so weird.....+1 though..
Jerry
@Jerry - Sorry, I forgot that I had added `position:relative` to my testing. That was your issue. Updated my answer to reflect it.
patrick dw
Nice!!!...Thanks a lot!!!! was wondering the reason of adding position:relative....:D
Jerry
I don't understand how it's supposed to work *anywhere* without `position`! `top` should not affect unpositioned elements at all.
bobince