Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery Animate - doesn't animate absolute DIV

do you know why i cant animate a absolute-positioning div with jQuery?

show please here (here is my example ):

http://jsfiddle.net/2VJe8/

HTML:

<html>
<body>
    <div class="test">
        <div class="box">
            <div class="arrow"></div> 
        </div>
        <a href="#" class="btnStartAni">Animate</a>
    </div>
</body>

CSS:

.test { margin: 0; padding: 0;}
.test .box { width: 150px; height: 140px; background-color: red; position: relative; }
.test .box .arrow { width: 50px; height: 50px; background-color: black; position: 
absolute; bottom: 0; right: -50px;}​

JavaScript:

jQuery(".test a.btnStartAni").on("click", function(e){
   e.preventDefault();
  jQuery(".box").animate({ width: 400}, 800);
});

the black box is during animation hide! But i dont know why?

can you help me please?

like image 488
mal200 Avatar asked Dec 15 '12 15:12

mal200


3 Answers

jQuery causes the overflow to be hidden when you use .animate, so change your code to

jQuery(".test a.btnStartAni").on("click", function(e){
    e.preventDefault();
    jQuery(".box").animate({ width: 400}, 800).css('overflow', 'visible');
});
​

And it should work

JsFiddle: http://jsfiddle.net/2VJe8/1/

Source: jQuery .animate() forces style "overflow:hidden"

like image 154
extramaster Avatar answered Nov 01 '22 17:11

extramaster


overflow: hidden gets set on .box when jQuery animates the box. .arrow overflows from .box and so disappears. Consider changing the markup.

like image 39
onions Avatar answered Nov 01 '22 17:11

onions


You can also re-arrange the elements to get the same effect (using float:left and display:inline-block)

http://jsfiddle.net/mkVrL/

like image 1
Steve Wellens Avatar answered Nov 01 '22 17:11

Steve Wellens