Html5百叶窗效果的示例代码

2022-10-20,,,,

本文介绍了html5百叶窗效果示例代码,分享给大家,具体如下:

实现方法介绍:

1,百叶窗布局 用定位(position: absolute)覆盖在content布局之上,背景设置为透明(background-color: transparent)
2,keyframes定义淡入淡出(透明度改变)和百叶窗口效果动画。
3,启动动画是通过设置dom的classname属性的方法,animator.classname = 'baiyewindow'; 监听动画完成事件'animationend',要清除classname属性。
4,在内容布局切换的事件,调用启动动画方法,两个布局都需要绑定切换事件 ng-click="switchlayout()"
5,动画执行时序图:

 

html代码:

<!--要显示百叶窗效果的布局--切换内容-->
<div id="fadeinout" class="content"  ng-click="switchlayout()">
...
</div>
<!--百叶窗布局-->
 <ul id="baiyewindow"  ng-click="switchlayout()">
       <li><div class="ye"></div></li>
        <li><div class="ye"></div></li>
        <li><div class="ye"></div></li>
        <li><div class="ye"></div></li>
  </ul>

css样式代码:

  //谈入谈出效果
 .fade-animation{
        @-webkit-keyframes fadeinout {
          0% {
            opacity: 1;
          }
          50% {
            opacity: 0;
          }
          100% {
            opacity: 1;
          }
        }
    @keyframes fadeinout {
          0% {
            opacity: 1;
          }
          50% {
            opacity: 0;
          }
          100% {
            opacity: 1;
          }
        }
        animation: fadeinout 1s ease-in;
        -webkit-animation: fadeinout 1s ease-in;
      }
      //百叶窗效果
      .baiyewindow{
        width: 100%;
        height: 1.68rem;
        position: absolute;
        left: 0;
        top: 1.2rem;
        li{
          height: 0.42rem;
          line-height: 40px;
          overflow: hidden;
          background-color: transparent;
          .ye{
            -webkit-animation: slideout 1s ease-in-out;
            animation: slideout 1s ease-in-out;
            width: 100%;
            background-color: rgba(0,0,0,.2);
            position: relative;
            top: 50%;
          }
        }
        @-webkit-keyframes slideout {
          0% {
            padding-bottom: 0;
            top: 50%;
          }
          100% {
            padding-bottom: 40px;
            top: 0;
          }
        }
        @keyframes slideout {
          0% {
            padding-bottom: 0;
            top: 50%;
          }
          100% {
            padding-bottom: 40px;
            top: 0;
          }
        }
      }

js代码:

//切换布局
$scope.switchlayout = function(){
    ...
    $scope.startbaiyewindow();
    //启动动画0.5s后,控制布局显示/隐藏
    $timeout(function () {
             if ($scope.show) {
                  $scope.show = false;
              } else {
                    ....
              }
     }, 500);
 }
//启动动画
        $scope.startbaiyewindow = function () {
            var animator = document.getelementbyid('baiyewindow');
            var animatorfadeinout = document.getelementbyid('fadeinout');
            animator.addeventlistener('animationend', function () {
                animator.classname = '';
                animatorfadeinout.classname = 'content';
            });
            $timeout(function () {
                animator.classname = 'baiyewindow';
                animatorfadeinout.classname = 'content fade-animation';
            }, 0);
        };

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

《Html5百叶窗效果的示例代码.doc》

下载本文的Word格式文档,以方便收藏与打印。