2016-07-19 1 views
1

私のページを開くと、私のテキストは画面中央にアニメーションで表示されます(私は "animate.css"を使用します)。そして、画面サイズに関係なく画面の上部に移動します。それを行う方法はありますか?テキストをアニメーション化してCSSの画面の上部に移動するにはどうすればいいですか?

私はどのようにテキストdivを中央に配置しましたか。

.center { 

     position: absolute; 
     margin: auto; 
     top: 0; 
     right: 0; 
     bottom: 0px; 
     left: 0; 
     width: 100%; 
     height: 170px; 
     background-color: red; 

    } 

私のアニメーション技術。 (下段の代わりに:300ピクセル、ページ上部に移動します)

.center:hover { 

     -webkit-animation: animationShrink 2s 1 ease forwards; 

    } 

    .container:hover { 

     -webkit-animation: animationUp 2s 1 ease forwards; 

    } 

    @-webkit-keyframes animationShrink { 

     from { 

      font-size: 1em; 

     } 
     to { 

      font-size: 0.6em; 

     } 

    } 

    @-webkit-keyframes animationUp { 

     from { 

      bottom: 0px; 

     } to { 

      bottom: 300px; 

     } 

    } 

ありがとうございました。

+0

ページ上部の画面の上部には?最初のケースでは、 'fixed'位置決めを使います。それを手伝って、それを手に入れることができなければ[jsfiddle](http://jsfiddlen.net)を作成してください。 – giorgio

+0

はい。私はそれをページの上部に移動して、私のメニュー項目がその側面に流れるようにしたい。しかし、私も滑らかなアニメーションが欲しいです。そして私は本当にあなたが固定配置を使って何を意味するかを得ることができませんでした。どこで使うべきですか? –

+0

'position:absolute'の代わりに' position:fixed'を試してください – Forty

答えて

0

HTML:

<a class='center'>Text</a> 

はCSS:

.center { 
    position: absolute; 
    left: 0; 
    top: calc(50vh - (170px/2)); 
    width: 100%; 
    height: 170px; 
    background-color: red; 
    -ms-transition: top 1s linear; 
    -moz-transition: top 1s linear; 
    -o-transition: top 1s linear; 
    -webkit-transition: top 1s linear; 
    transition: top 1s linear; 

} 

.center:active { 
    top: 0; 
    -ms-transition: top 2s linear; 
    -moz-transition: top 2s linear; 
    -o-transition: top 2s linear; 
    -webkit-transition: top 2s linear; 
    transition: top 2s linear; 
} 

例えば、このplunkerをチェックしてください: https://plnkr.co/edit/GvH176vMGKSD47VrleXQ?p=preview

を私は(上のクリックしてアクティブにアニメーションを開始するには、 "アクティブ" 疑似クラスを使用要素、たとえばちょうど)。このコードは、カスタマイズのための良い基盤を提供するはずです。

関連する問題