[CSS] @keyframes


@keyframes swing{
  0% { transform: rotate(0deg)}
  100% {transform: rotate(-30deg)}
}

#sweetlandia{
    animation: swing 2s infinite ease-in-out;
}



Muli-steps keyframes

@keyframes swing {
  0% {
    transform: rotate(-30deg);
  }

  50% {
    transform: rotate(30deg);
  }

  100% {
    transform: rotate(-30deg);
  }
}

#sweetlandia {
  animation: swing 2s infinite ease-in-out;
}
@keyframes swing {
  0%, 100% { transform: rotate(-30deg); }
  20% {transform: scale(0.95)}
  80% {transform: scale(0.95)}
  50% { transform: rotate(30deg); }
}

#sweetlandia {
  animation: swing 2s infinite ease-in-out;
}

More Advanced Keyframe Animations

fadeIn keyframe animation has been started. Style the element to be completely hidden in its starting state. Hide it in a way that will allow us to fade it in.

@keyframes fadeIn {
  0% {
    opacity: 0;
    visibility: hidden;
  }
  100% {

  }
}

Complete the animation by making the end state visible.

@keyframes fadeIn {
  0% {
    opacity: 0;
    visibility: hidden;
  }
  100% {
        opacity: 1;
    visibility: visible;
  }
}

Apply the fadeIn animation to the .modal-overlay when it is .active.

@keyframes fadeIn {
  0% {
    opacity: 0;
    visibility: hidden;
  }
  100% {
        opacity: 1;
    visibility: visible;
  }
}

.modal-overlay.active{
    animation: fadeIn .25s;
}

Finally, in order to make the overlay stay visible after it is done animating, give the animation a fill-mode of forwards.

@keyframes fadeIn {
  0% {
    opacity: 0;
    visibility: hidden;
  }
  100% {
        opacity: 1;
    visibility: visible;
  }
}

.modal-overlay.active{
    animation: fadeIn .25s forwards;
}

Create a slideUp keyframe animation.

Have the slideUp animation start by moving down (translating Y) by 400px.

End the animation by moving up (translating Y) by -300px up the page.

@keyframes slideUp{
  from {
      transform: translateY(400px);
  }
  to{
    transform: translateY(-300px);
  }
}

The fadeIn animation has already been applied for you to the modal when active. Now apply the newly created slideUp animation. Give the animation a0.65s duration with a 0.5s delay.

.modal.active {
  animation: fadeIn 0.25s forwards, slideUp 0.65s 0.5s;
}

Give the slideUp animation a custom cubic bezier with these values 0.175, 0.885, 0.32, 1.275. This will cause the modal to slideUp, overshoot the -300px, and then slide back down to its resting spot at -300px. Neat, right?!

Finally, have the modal stay at its final resting state on the page, by giving theslideUp animation a fill-mode of forwards.

@keyframes slideUp{
  from {
      transform: translateY(400px);
  }
  to{
    transform: translateY(-300px);
  }
}

.modal.active {
  animation: fadeIn 0.25s forwards, slideUp 0.65s 0.5s cubic-bezier(0.175,0.885,0.32,1.275) forwards;
}
<!DOCTYPE>
<html lang=‘en‘>
  <head>
    <meta charset=‘utf-8‘>
    <title>Cosplay Happenings</title>
    <link href=‘level3.css‘ rel=‘stylesheet‘ type=‘text/css‘>
  </head>
  <body>
    <!-- Nav -->
    <nav class=‘nav‘>
      <div class=‘cell‘>
        <a class=‘nav-logo‘ href=‘/‘>
          <div class=‘shing‘>
            <img src=‘logo.png‘ alt=‘Sweet Lands‘ />
          </div>
        </a>
        <ul class=‘nav-menu‘>
          <li><a href=‘#retweets‘>Retweets</a></li>
          <li><a href=‘#pictures‘>Pictures</a></li>
          <li><a href=‘#event‘>Upcoming</a></li>
        </ul>
      </div>
    </nav>

    <!-- Header -->
    <header class=‘header‘>
      <div class=‘cell well‘>
        <h1 class=‘header-title‘>Cosplay Happenings</h1>
        <p class=‘header-subtitle‘>Welcome to our candy-coated community!</p>
      </div>
    </header>

    <!-- Most Retweeted -->
    <section class=‘retweets‘ id=‘retweets‘>
      <div class=‘cell well‘>
        <h2>Most Retweeted</h2>
        <div class=‘retweet group‘>
          <img src=‘unicorn.jpg‘ alt=‘Unicorn‘ width=‘200‘ height=‘200‘ />
          <p>
            Sparkles the Unicorn saunters down the Lemony Brick Road and
            prances past the Soda Pop River! Her majestic horn points the way
            to the Frosting Fortress, as her glittery mane and tail sway in the
            bubblegum breeze.
          </p>
        </div>
        <div class=‘retweet group‘>
          <img src=‘fairy.jpg‘ alt=‘Fairy‘ width=‘200‘ height=‘200‘ />
          <p>
            Who’s that there in the Candy Corn Fields? Why, it’s Sarsaparilla
            the Sherbet Sprite! He’s thoughtfully pondering which treat to
            partake of next. The Lollipop Forest is in the distance, in case he
            needs a place to rest his sweet head.
          </p>
        </div>
      </div>
    </section>

    <!-- Purchase -->
    <section class=‘pictures‘ id=‘pictures‘>
      <div class=‘cell well‘>
        <h2>Pictures</h2>
        <ul class=‘pictures-list group‘>
          <li><img src=‘group-01.jpg‘ alt=‘Group‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘cupcake.jpg‘ alt=‘Cupcake‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘rainbow.jpg‘ alt=‘Rainbow‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘donut.jpg‘ alt=‘Donut‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘dog.jpg‘ alt=‘Dog‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘fairy.jpg‘ alt=‘Fairy‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘unicorn.jpg‘ alt=‘Unicorn‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘group-02.jpg‘ alt=‘Group‘ width=‘200‘ height=‘200‘ /></li>
        </ul>
      </div>
    </section>

    <!-- Contact -->
    <section class=‘event‘  id=‘event‘>
      <div class=‘cell well‘>
        <h2>Upcoming Event</h2>
        <div class=‘event-content‘>
          <img src=‘sweetlandia.png‘ alt=‘SweetLandia‘ id=‘sweetlandia‘ width=‘200‘ />
          <h3>SweetLandia</h3>
          <p>
            Once upon a time, there was a magical place called Sweet Lands — a
            world we may now only travel to in our imaginations. But one
            weekend every year, when the sugar cane stalks bend toward the east
            and the cotton candy is at its swirliest, the Sweetlandia
            convention brings this wondrous world within reach! So join
            Sparkles, Pierre, and the rest of the gang for a meeting of the
            sweet-minded in sunny Omaha, Nebraska! It’s sure to be your
            sweetest adventure yet.
          </p>
          <div class=‘event-action‘>
            <a href=‘#‘ class=‘btn buy-button‘>
              <span class=‘top content‘>Register Now!</span>
              <span class=‘bottom content‘>Hurry, Limited Space!</span>
            </a>
          </div>
        </div>
      </div>
    </section>

    <!-- Register Modal -->
    <div class=‘modal-overlay‘></div>
    <div class=‘modal‘>
      <div class=‘modal-header‘>
        <a class=‘modal-close‘ href=‘#‘ aria-label=‘Close‘>&times;</a>
        <h3>Register</h3>
      </div>
      <div class=‘modal-content‘>
        <form class=‘form‘ action=‘‘>
          <fieldset class=‘form-field‘>
            <!-- <label class=‘form-label‘ for=‘type‘>CC Type</label> -->
            <select class=‘cs-select cs-skin-elastic‘ name=‘type‘>
              <option value=‘visa‘>Visa</option>
              <option value=‘mastercard‘>MasterCard</option>
              <option value=‘american_express‘>American Express</option>
            </select>
          </fieldset>

          <fieldset class=‘form-field‘>
            <input class=‘form-input‘ type=‘text‘ id=‘number‘ />
            <label class=‘form-label‘ for=‘number‘>CC Number</label>
          </fieldset>

          <fieldset class=‘form-field‘>
            <input class=‘form-input‘ type=‘text‘ id=‘expiration‘ />
            <label class=‘form-label‘ for=‘expiration‘>CC Expiration</label>
          </fieldset>

          <div class=‘form-submit‘>
            <input class=‘btn‘ type=‘Submit‘ value=‘Submit‘ />
          </div>
        </form>
      </div>
    </div>
    <script src=‘application.min.js‘></script>
  </body>
</html>


Apply the slideUpSmall animation to the modal‘s header using a 0.25second duration.

Give the slideUpSmall animation a 0.75 second delay and a fill-mode offorwards.

Nice job! Now apply the slideUpSmall animation to the modal‘s content using the same duration as before.

Give the slideUpSmall animation for the modal‘s content a 0.8 second delay and a fill-mode of forwards.

@keyframes fadeIn {
  0% {
    opacity: 0;
    visibility: hidden;
  }
  100% {
    opacity: 1;
    visibility: visible;
  }
}
.modal-overlay.active {
  animation: fadeIn 0.25s forwards ;
}
@keyframes slideUp {
  from {transform: translateY(400px);}
  to   {transform: translateY(-300px);}
}
.modal {
  transform: translateY(700px);
}
.modal.active {
  animation: fadeIn 0.25s forwards,
    slideUp 0.65s 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

@keyframes slideUpSmall {
  from {transform: translateY(80px);}
  to   {transform: translateY(0px);}
}

.modal.active .modal-header {
  animation: fadeIn 0.25s 0.8s forwards, slideUpSmall 0.25s 0.75s forwards;
}

.modal.active .modal-content {
  animation: fadeIn 0.25s 0.85s forwards, slideUpSmall 0.25s 0.8s forwards;
}
<!DOCTYPE>
<html lang=‘en‘>
  <head>
    <meta charset=‘utf-8‘>
    <title>Cosplay Happenings</title>
    <link href=‘level3.css‘ rel=‘stylesheet‘ type=‘text/css‘>
  </head>
  <body>
    <!-- Nav -->
    <nav class=‘nav‘>
      <div class=‘cell‘>
        <a class=‘nav-logo‘ href=‘/‘>
          <div class=‘shing‘>
            <img src=‘logo.png‘ alt=‘Sweet Lands‘ />
          </div>
        </a>
        <ul class=‘nav-menu‘>
          <li><a href=‘#retweets‘>Retweets</a></li>
          <li><a href=‘#pictures‘>Pictures</a></li>
          <li><a href=‘#event‘>Upcoming</a></li>
        </ul>
      </div>
    </nav>

    <!-- Header -->
    <header class=‘header‘>
      <div class=‘cell well‘>
        <h1 class=‘header-title‘>Cosplay Happenings</h1>
        <p class=‘header-subtitle‘>Welcome to our candy-coated community!</p>
      </div>
    </header>

    <!-- Most Retweeted -->
    <section class=‘retweets‘ id=‘retweets‘>
      <div class=‘cell well‘>
        <h2>Most Retweeted</h2>
        <div class=‘retweet group‘>
          <img src=‘unicorn.jpg‘ alt=‘Unicorn‘ width=‘200‘ height=‘200‘ />
          <p>
            Sparkles the Unicorn saunters down the Lemony Brick Road and
            prances past the Soda Pop River! Her majestic horn points the way
            to the Frosting Fortress, as her glittery mane and tail sway in the
            bubblegum breeze.
          </p>
        </div>
        <div class=‘retweet group‘>
          <img src=‘fairy.jpg‘ alt=‘Fairy‘ width=‘200‘ height=‘200‘ />
          <p>
            Who’s that there in the Candy Corn Fields? Why, it’s Sarsaparilla
            the Sherbet Sprite! He’s thoughtfully pondering which treat to
            partake of next. The Lollipop Forest is in the distance, in case he
            needs a place to rest his sweet head.
          </p>
        </div>
      </div>
    </section>

    <!-- Purchase -->
    <section class=‘pictures‘ id=‘pictures‘>
      <div class=‘cell well‘>
        <h2>Pictures</h2>
        <ul class=‘pictures-list group‘>
          <li><img src=‘group-01.jpg‘ alt=‘Group‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘cupcake.jpg‘ alt=‘Cupcake‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘rainbow.jpg‘ alt=‘Rainbow‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘donut.jpg‘ alt=‘Donut‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘dog.jpg‘ alt=‘Dog‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘fairy.jpg‘ alt=‘Fairy‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘unicorn.jpg‘ alt=‘Unicorn‘ width=‘200‘ height=‘200‘ /></li>
          <li><img src=‘group-02.jpg‘ alt=‘Group‘ width=‘200‘ height=‘200‘ /></li>
        </ul>
      </div>
    </section>

    <!-- Contact -->
    <section class=‘event‘  id=‘event‘>
      <div class=‘cell well‘>
        <h2>Upcoming Event</h2>
        <div class=‘event-content‘>
          <img src=‘sweetlandia.png‘ alt=‘SweetLandia‘ id=‘sweetlandia‘ width=‘200‘ />
          <h3>SweetLandia</h3>
          <p>
            Once upon a time, there was a magical place called Sweet Lands — a
            world we may now only travel to in our imaginations. But one
            weekend every year, when the sugar cane stalks bend toward the east
            and the cotton candy is at its swirliest, the Sweetlandia
            convention brings this wondrous world within reach! So join
            Sparkles, Pierre, and the rest of the gang for a meeting of the
            sweet-minded in sunny Omaha, Nebraska! It’s sure to be your
            sweetest adventure yet.
          </p>
          <div class=‘event-action‘>
            <a href=‘#‘ class=‘btn buy-button‘>
              <span class=‘top content‘>Register Now!</span>
              <span class=‘bottom content‘>Hurry, Limited Space!</span>
            </a>
          </div>
        </div>
      </div>
    </section>

    <!-- Register Modal -->
    <div class=‘modal-overlay‘></div>
    <div class=‘modal‘>
      <div class=‘modal-header‘>
        <a class=‘modal-close‘ href=‘#‘ aria-label=‘Close‘>&times;</a>
        <h3>Register</h3>
      </div>
      <div class=‘modal-content‘>
        <form class=‘form‘ action=‘‘>
          <fieldset class=‘form-field‘>
            <!-- <label class=‘form-label‘ for=‘type‘>CC Type</label> -->
            <select class=‘cs-select cs-skin-elastic‘ name=‘type‘>
              <option value=‘visa‘>Visa</option>
              <option value=‘mastercard‘>MasterCard</option>
              <option value=‘american_express‘>American Express</option>
            </select>
          </fieldset>

          <fieldset class=‘form-field‘>
            <input class=‘form-input‘ type=‘text‘ id=‘number‘ />
            <label class=‘form-label‘ for=‘number‘>CC Number</label>
          </fieldset>

          <fieldset class=‘form-field‘>
            <input class=‘form-input‘ type=‘text‘ id=‘expiration‘ />
            <label class=‘form-label‘ for=‘expiration‘>CC Expiration</label>
          </fieldset>

          <div class=‘form-submit‘>
            <input class=‘btn‘ type=‘Submit‘ value=‘Submit‘ />
          </div>
        </form>
      </div>
    </div>
    <script src=‘application.min.js‘></script>
  </body>
</html>
时间: 2024-10-14 06:48:51

[CSS] @keyframes的相关文章

css @keyframes属性 语法

css @keyframes属性 语法 @keyframes是什么?直线电机生产厂家 @keyframes是CSS的一种规则,可以用来定义CSS动画的一个周期的行为,创建简单的动画. 作用:通过 @keyframes 规则,您能够创建动画. 说明:创建动画的原理是,将一套 CSS 样式逐渐变化为另一套样式.在动画过程中,您能够多次改变这套 CSS 样式.以百分比来规定改变发生的时间,或者通过关键词 "from" 和 "to",等价于 0% 和 100%.0% 是动画

[TypeStyle] Use TypeStyle keyframes to create CSS animations

We cover CSS keyframes and how to create them using TypeStyle. We then show how to use the keyframes function to create an animation. We also discuss a few other CSS properties in the animation namespace. import {style, keyframes, classes} from 'type

css中animation和@keyframes 动画

Animation 使用简写属性,将动画与 div 元素绑定: div { animation:mymove 5s infinite; -webkit-animation:mymove 5s infinite; /* Safari 和 Chrome */ } Internet Explorer 10.Firefox 以及 Opera 支持 animation 属性. Safari 和 Chrome 支持替代的 -webkit-animation 属性. 注释:Internet Explorer

CSS笔记(十二)CSS3之动画

参考:http://www.w3school.com.cn/css3/css3_animation.asp 通过 CSS3,我们能够创建动画,这可以在许多网页中取代动画图片.Flash 动画以及 JavaScript. CSS3 动画属性 下面的表格列出了 @keyframes 规则和所有动画属性: 属性 描述 CSS @keyframes 规定动画. 3 animation 所有动画属性的简写属性,除了 animation-play-state 属性. 3 animation-name 规定

2016年11月10日--CSS动画

jquery动画:http://www.w3school.com.cn/jquery/jquery_animate.aspCSS3动画教程1:http://www.w3school.com.cn/css3/css3_animation.aspCSS3动画教程2:http://www.runoob.com/css3/css3-animations.html . CSS3的动画属性 下面的表格列出了 @keyframes 规则和所有动画属性: 属性 描述 CSS @keyframes 规定动画. 3

什么是css动画

动画是使元素从一种样式逐渐变化为另一种样式的效果. 您可以改变任意多的样式任意多的次数. 请用百分比来规定变化发生的时间,或用关键词 "from" 和 "to",等同于 0% 和 100%. 0% 是动画的开始,100% 是动画的完成. 为了得到最佳的浏览器支持,您应该始终定义 0% 和 100% 选择器. 实例 当动画为 25% 及 50% 时改变背景色,然后当动画 100% 完成时再次改变: @keyframes myfirst { 0% {background

CSS参考手册

CSS 属性 CSS 属性组: 动画 背景 边框和轮廓 盒(框) 颜色 内容分页媒体 定位 可伸缩框 字体 生成内容 网格 超链接 行框 列表 外边距 Marquee 多列 内边距 分页媒体 定位 打印 Ruby 语音 表格 文本 2D/3D 转换 过渡 用户界面 "CSS" 列指示该属性是在哪个 CSS 版本(CSS1.CSS3 或 CSS3)中定义的. CSS3 动画属性(Animation) 属性 描述 CSS @keyframes 规定动画. 3 animation 所有动画属

CSS 参考手册

动画属性 属性 描述 CSS @keyframes 定义一个动画,@keyframes定义的动画名称用来被animation-name所使用. 3 animation 复合属性.检索或设置对象所应用的动画特效. 3 animation-name 检索或设置对象所应用的动画名称 ,必须与规则@keyframes配合使用,因为动画名称由@keyframes定义 3 animation-duration 检索或设置对象动画的持续时间 3 animation-timing-function     检索

[技术] 如何正确食用cnblogs的CSS定制

用过cnblogs的估计都知道cnblogs提供了相对比较开放的个性化选项,其中最为突出的估计就是页面CSS定制了.但是没学过Web前端的人可能并不会用这个东西... 所以我打算在此分享一些定制CSS过程中使用的奇技淫巧一些方法来帮助大家定制blog qwq 博主并非专业Web开发,所以可能有些语言不够严谨或者不够准确还请谅解qwq 如果有表意模糊的地方也欢迎留言qwq 1.何谓CSS CSS,即层叠样式表,可以被认为是HTML的扩充,用于给HTML里结构化的内容指定显示方式,比如字体/背景/大