首頁  >  文章  >  web前端  >  Html5百葉窗效果的範例程式碼_html5教學技巧

Html5百葉窗效果的範例程式碼_html5教學技巧

韦小宝
韦小宝原創
2017-12-16 10:42:202890瀏覽

這篇文章主要介紹了Html5百葉窗效果的範例程式碼,小編覺得挺不錯的,現在分享給大家HTML5原始碼和解釋,也給大家做個參考。對HTML5有興趣的夥伴可以一起跟著小編過來看看吧

本文介紹了Html5百葉窗效果的範例程式碼,分享給大家,具體如下:

實作方法介紹:

1,百葉窗佈局以定位(position: absolute)覆蓋在content佈局之上,背景設定為透明(background-color: transparent)
2,keyframes定義淡入淡出(透明度改變)和百葉窗效果動畫。
3,啟動動畫是透過設定DOM的className屬性的方法,animator.className = 'baiyeWindow'; 監聽動畫完成事件'animationend',要清除className屬性。
4,在內容佈局切換的事件,呼叫啟動動畫方法,兩個佈局都需要綁定切換事件ng-click="switchLayout()"
5,動畫執行時序圖:


 

html程式碼:


#
<!--要显示百叶窗效果的布局--切换内容-->
<p id="fadeInOut" class="content"  ng-click="switchLayout()">
...
</p>
<!--百叶窗布局-->
 <ul id="baiyeWindow"  ng-click="switchLayout()">
       <li><p class="ye"></p></li>
        <li><p class="ye"></p></li>
        <li><p class="ye"></p></li>
        <li><p class="ye"></p></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(&#39;baiyeWindow&#39;);
            var animatorFadeInOut = document.getElementById(&#39;fadeInOut&#39;);
            animator.addEventListener(&#39;animationend&#39;, function () {
                animator.className = &#39;&#39;;
                animatorFadeInOut.className = &#39;content&#39;;
            });
            $timeout(function () {
                animator.className = &#39;baiyeWindow&#39;;
                animatorFadeInOut.className = &#39;content fade-animation&#39;;
            }, 0);
        };


以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持PHP中文網。

相關推薦:

#最完整的HTML5全域屬性匯總

在行動裝置HTML5中判斷橫螢幕垂直畫面的方法

HTML5單一頁面手勢滑幕切換原理分析

#

以上是Html5百葉窗效果的範例程式碼_html5教學技巧的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn