Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery slice div into animatable segments

is it possible using jQuery and CSS to split a div in two, and then animate the two parts separately?

To better explain, see this diagram:

enter image description here enter image description here

Any help would be much appreciated - thanks in advance.

like image 746
jacktheripper Avatar asked Jul 31 '26 02:07

jacktheripper


2 Answers

You can fake it with a pair of container divs like this: jsFiddle example.

HTML

<div id="top"><div>Some text here</div></div>
<div id="bottom"><div>Some text here</div></div>​

CSS

#top,#bottom {
    background: #333;
    width:200px;
    height:100px;
    position:relative;
    overflow:hidden;
}
#top div {
    position:relative;
    top: 90px;
    color:#eee;
    text-align:center;
}
#bottom div {
    position:relative;
    top: -10px;
    color:#eee;
    text-align:center;
}

jQuery

$('#bottom').delay(2000).animate({
    bottom: '-200px'
},4000);
$('#top').delay(2000).animate({
    top: '-200px'
},4000);

like image 60
j08691 Avatar answered Aug 02 '26 14:08

j08691


No, you can't show one div like that. But you could duplicate and restrict size to half on each copy, then animate both.

like image 28
Amadan Avatar answered Aug 02 '26 14:08

Amadan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!