最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - jQuery slice div into animatable segments - Stack Overflow

programmeradmin1浏览0评论

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:

Any help would be much appreciated - thanks in advance.

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:

Any help would be much appreciated - thanks in advance.

Share Improve this question asked Jun 18, 2012 at 16:37 jacktheripperjacktheripper 14.3k12 gold badges60 silver badges93 bronze badges 1
  • 1 If you end up doing it yourself, take a look at jQuery UI's explode effect for inspiration: docs.jquery./UI/Effects/Explode (it works with text) – thirtydot Commented Jun 18, 2012 at 16:41
Add a ment  | 

3 Answers 3

Reset to default 6

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);

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

you could make 2 divs, and have each set with overflow:hidden;.

After that, place the text at same position left, but one slightly below it's div and one slightly above so that each text is 'cut' in half. (or this is one work-around to do it)

发布评论

评论列表(0)

  1. 暂无评论