2018-06-19 13:51:39 2067瀏覽
本篇文章扣丁學(xué)堂HTML5培訓(xùn)小編給大家分享下HTML5百葉窗效果如何用代碼敲出來(lái),文章中會(huì)有詳細(xì)的代碼列出,喜歡HTML5開(kāi)發(fā)的小伙伴可以隨小編看一下。
實(shí)現(xiàn)方法介紹:
1、百葉窗布局 用定位(position: absolute)覆蓋在content布局之上,背景設(shè)置為透明(background-color: transparent)
2、keyframes定義淡入淡出(透明度改變)和百葉窗口效果動(dòng)畫。
3、啟動(dòng)動(dòng)畫是通過(guò)設(shè)置DOM的className屬性的方法,animator.className = 'baiyeWindow'; 監(jiān)聽(tīng)動(dòng)畫完成事件'animationend',要清除className屬性。
4、在內(nèi)容布局切換的事件,調(diào)用啟動(dòng)動(dòng)畫方法,兩個(gè)布局都需要綁定切換事件 ng-click="switchLayout()"
5、動(dòng)畫執(zhí)行時(shí)序圖:
html代碼:
<!--要顯示百葉窗效果的布局--切換內(nèi)容--> <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(); //啟動(dòng)動(dòng)畫0.5s后,控制布局顯示/隱藏 $timeout(function () { if ($scope.show) { $scope.show = false; } else { .... } }, 500); } //啟動(dòng)動(dòng)畫 $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百葉窗效果的示例代碼,希望對(duì)小伙伴們有所幫助,想要了解更多內(nèi)容的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢。扣丁學(xué)堂是專業(yè)的HTML5培訓(xùn)機(jī)構(gòu),扣丁學(xué)堂不僅有專業(yè)的老師和與時(shí)俱進(jìn)的課程體系,還有大量的HTML5在線教程供學(xué)員觀看學(xué)習(xí)哦。扣丁學(xué)堂H5技術(shù)交流群:559883758。
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“HTML5開(kāi)發(fā)技術(shù)資訊”的相關(guān)文章>>