jQuery .animate() marginLeft not working in IE8 an

2019-09-16 17:27发布

问题:

I have an IE specific problem. On the bright side it works well on all other browsers.

The problem occurs when clicking the .close_button_page image which should perform the simple animate function, moving the div to the left.

In IE 8 and below, it simply says invalid argument in the console. I have found issues like this online but none address the problem.

Note: There are many other IE bugs (z-index etc) at the moment so please ignore that.

HTML:

<div id="content-left">
    <img class="close_button_page" height="13" width="14" src="assets/images/close_button.png"/>
    <h2>Our process</h2>
    <h3>Even smaller title to this section</h3>
    <p>Dummy text to show that this is the home of Dukelease and that this site is of the utmost quality and will provide hours of fun by flicking through images.</p>
</div>

CSS:

#content-left {
  -webkit-box-shadow:#000000 1px 1px 5px;
  border-top-color:#FFFFFF;
  border-top-style:solid;
  border-top-width:3px;
  box-shadow:#000000 1px 1px 5px;
  float:left;
  padding-bottom:10px;
  padding-left:10px;
  padding-right:10px;
  padding-top:10px;
  position:relative !important;
  width:230px;
  z-index:10;
}
style.css (line 562)
#content-left, .bg_white {
  background-color:rgba(255, 255, 255, 0.949219);
}

JavaScript:

$(".close_button_page").click(function(){   

    $('#content-left').animate({
        marginLeft: '-260px'
    }, 1300, function(){
        $('.open_button_page').fadeIn(1000);
    });             
});

回答1:

Try replacing this:

$(".close_button_page").click(function(){   

    $('#content-left').animate({
        marginLeft: '-260px'
    }, 1300, function(){
        $('.open_button_page').fadeIn(1000);
    });             
});

with this:

$(".close_button_page").click(function(){ 
    $('#content-left').toggle('slide');
});

Tested here http://jsfiddle.net/ollie101/RuVZ3/5/