I’m using jQuery’s animate() and it just doesn’t work. I’m trying to get a div to slide off another div that’s containing it and has overflow:hidden. I’ve tried every combination of left on the animate and nothing. Just to make sure, I also tried changing the width of the div (gallery) and it does change the width, but not the left.
What am I doing wrong?
function an() {
//$('#gallery').fadeOut();
//$('#gallery').animate({left:'-=1000'},'slow');
$('#gallery').animate({
'left': '+=100px'
}, 'slow');
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<div align="center" style="position:relative; height:137px; overflow:hidden; width:1000px; border:3px solid #ff0000;">
<div id="gallery" style="background-color:#033; width:100px; height:137px;"></div>
</div>
<a href="#" onclick="an(); return false;">test</a>
You should give the #gallery div a
position:relativeand then it works fine.View on JSFiddle
By the way, you should avoid inline JavaScript (like onclick) and CSS whenever possible. Also, the
alignattribute was deprecated in HTML 4.01 and eliminated in HTML5.