Animation Addons in React

Sometimes we need some effect of animation when the components mounted or unmounted, if using the React API, we have so much work to do like that change class by componentDidMount or ComponentWIllUnmount .Lucky there has a choose to reach our goal .

import CSSTransitionGroup from 'react-addons-css-transition-group';

With Addons we can easily avoid difficulties .

const renderCard = ({ title, id, date, brief, genre, image }, key) =>
      <Card
        key={key}
        id={id}
        title={title}
        date={date}
        brief={brief}
        genre={genre}
        image={image}
      />;
    return (
      <CSSTransitionGroup
        component={Panel}
        transitionName="card"
        transitionEnterTimeout={500}
        transitionLeaveTimeout={300}
      >
        {matchCard().map(renderCard)}
      </CSSTransitionGroup>
    );
  }

This is a render function.

  1. component : what tag we want the CSSTransitionGroup it actually is . span is the default.
  2. transitionName: a very important property which we will assign the animation within which class.
  3. transitionEnterTimeout and transitionLeaveTimeout to specify how long the animation time we want.
  4. Just the child components will have animations , so must parse the child component into the CSSTransitionGroup.

So .. after mounting , the components will be added a class named card-enter. what name we assign in the transitionName what prefix will be specified.

.card-enter {
    opacity: 0;
  }

.card-enter.card-enter-active {
    opacity: 1;
  }

Now our components named Card will fade in and fade out.

If using moduleCSS you must use global style.

:global{
  .card-enter {
    opacity: 0;
    transform: scale(1.5);
  }
  .card-enter.card-enter-active {
    opacity: 1;
    transform: scale(1);
  }
  .card-leave {
    opacity: 0.1;
  }
}

Like this...

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末诫隅,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子调俘,更是在濱河造成了極大的恐慌术荤,老刑警劉巖碑定,帶你破解...
    沈念sama閱讀 221,273評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件天通,死亡現(xiàn)場離奇詭異娃肿,居然都是意外死亡疾嗅,警方通過查閱死者的電腦和手機豪嗽,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,349評論 3 398
  • 文/潘曉璐 我一進店門谴蔑,熙熙樓的掌柜王于貴愁眉苦臉地迎上來豌骏,“玉大人,你說我怎么就攤上這事隐锭∏远悖” “怎么了?”我有些...
    開封第一講書人閱讀 167,709評論 0 360
  • 文/不壞的土叔 我叫張陵钦睡,是天一觀的道長蒂窒。 經(jīng)常有香客問我,道長荞怒,這世上最難降的妖魔是什么洒琢? 我笑而不...
    開封第一講書人閱讀 59,520評論 1 296
  • 正文 為了忘掉前任,我火速辦了婚禮褐桌,結(jié)果婚禮上衰抑,老公的妹妹穿的比我還像新娘。我一直安慰自己荧嵌,他們只是感情好呛踊,可當我...
    茶點故事閱讀 68,515評論 6 397
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著完丽,像睡著了一般恋技。 火紅的嫁衣襯著肌膚如雪拇舀。 梳的紋絲不亂的頭發(fā)上逻族,一...
    開封第一講書人閱讀 52,158評論 1 308
  • 那天,我揣著相機與錄音骄崩,去河邊找鬼聘鳞。 笑死,一個胖子當著我的面吹牛要拂,可吹牛的內(nèi)容都是我干的抠璃。 我是一名探鬼主播,決...
    沈念sama閱讀 40,755評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼脱惰,長吁一口氣:“原來是場噩夢啊……” “哼搏嗡!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起拉一,我...
    開封第一講書人閱讀 39,660評論 0 276
  • 序言:老撾萬榮一對情侶失蹤采盒,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后蔚润,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體磅氨,經(jīng)...
    沈念sama閱讀 46,203評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,287評論 3 340
  • 正文 我和宋清朗相戀三年嫡纠,在試婚紗的時候發(fā)現(xiàn)自己被綠了烦租。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片延赌。...
    茶點故事閱讀 40,427評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖叉橱,靈堂內(nèi)的尸體忽然破棺而出挫以,到底是詐尸還是另有隱情,我是刑警寧澤赏迟,帶...
    沈念sama閱讀 36,122評論 5 349
  • 正文 年R本政府宣布屡贺,位于F島的核電站,受9級特大地震影響锌杀,放射性物質(zhì)發(fā)生泄漏甩栈。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,801評論 3 333
  • 文/蒙蒙 一糕再、第九天 我趴在偏房一處隱蔽的房頂上張望量没。 院中可真熱鬧,春花似錦突想、人聲如沸殴蹄。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,272評論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽袭灯。三九已至,卻和暖如春绑嘹,著一層夾襖步出監(jiān)牢的瞬間稽荧,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,393評論 1 272
  • 我被黑心中介騙來泰國打工工腋, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留姨丈,地道東北人。 一個月前我還...
    沈念sama閱讀 48,808評論 3 376
  • 正文 我出身青樓擅腰,卻偏偏與公主長得像蟋恬,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子趁冈,可洞房花燭夜當晚...
    茶點故事閱讀 45,440評論 2 359

推薦閱讀更多精彩內(nèi)容