对话框/Tips

微软Xbox One样式消息框特效

阿里云

这是一款仿照微软 Xbox One 样式的消息框制作的 jQuery 和 CSS3 通知消息框特效。该消息框分为三个部分,每个部分在消息框被激活时将依次打开,再依次关闭,效果非常的酷。

HTML 结构:

该消息框的 HTML 结构如下,主要结构分为三个部分:div.impact,div.message-container 和一个[h1]标签。

也想出现在这里?联系我们
创客主机
  1. <div class="pull">
  2.   <div class="notification positive">
  3.   <div class="flex-container">
  4.       <div class="impact">
  5.         <div class="icon">
  6.           <i class="fa fa-gamepad"></i>
  7.         </div>
  8.       </div>
  9.       <div class="message-container">
  10.         <div class="message">
  11.           <strong>jQueryScript is online</strong>
  12.         </div>
  13.       </div>
  14.     </div>
  15.     <h1>Hold <img src="xbox.png" alt="" class="xbox-logo"> to launch</h1>
  16.   </div>
  17. </div>

CSS 样式:

该消息框的包裹容器被制作为 3D 空间。

  1. .pull {
  2.   position: fixed;
  3.   bottom: 0;
  4.   width: 100%;
  5.   -webkit-perspective: 250px;
  6.           perspective: 250px;
  7.   -webkit-perspective-origin: right center;
  8.           perspective-origin: right center;
  9.   -webkit-transition: -webkit-perspective .1s ease;
  10.           transition: perspective .1s ease;
  11. }
  12. .pull.open {
  13.   -webkit-perspective: 500px;
  14.           perspective: 500px;
  15. }

消息框的布局采用 flexbox 的布局方式。

  1. .notification .flex-container {
  2.   display: -webkit-box;
  3.   display: -webkit-flex;
  4.   display: -ms-flexbox;
  5.   display: flex;
  6.   -webkit-box-orient: horizontal;
  7.   -webkit-box-direction: normal;
  8.   -webkit-flex-direction: row;
  9.       -ms-flex-direction: row;
  10.           flex-direction: row;
  11.   -webkit-flex-wrap: no-wrap;
  12.       -ms-flex-wrap: no-wrap;
  13.           flex-wrap: no-wrap;
  14.   -webkit-box-align: stretch;
  15.   -webkit-align-items: stretch;
  16.       -ms-flex-align: stretch;
  17.           align-items: stretch;
  18.   -webkit-transition: -webkit-transform .35s ease;
  19.           transition: transform .35s ease;
  20.   -webkit-transform: translate3d(0, 45px, 0);
  21.           transform: translate3d(0, 45px, 0);
  22. }
  23. .notification .flex-container.drop-down {
  24.   -webkit-transform: translate3d(0, 0, 0);
  25.           transform: translate3d(0, 0, 0);
  26. }

其中 transform: translate3d(0, 0, 0);用于性能优化,开启 GPU。

JAVASCRIPT 代码:

核心的 jQuery 代码如下,有两个函数:openNotification()和 closeNotification()分别用于打开和关闭消息框:

  1. $(function () {
  2.     $('.notification').addClass('notification-hidden');
  3.     openNotification('positive');
  4.     setTimeout(closeNotification, 10000);
  5. });
  6. $('.again').click(function () {
  7.     openNotification('positive');
  8.     setTimeout(closeNotification, 10000);
  9. });
  10. function openNotification(whichNotification) {
  11.     var thisNotification = $('.notification.' + whichNotification);
  12.     thisNotification.removeClass('notification-hidden');
  13.     setTimeout(function () {
  14.         thisNotification.addClass('open');
  15.         var openNotification = $('.notification.open');
  16.         $('.pull').addClass('open');
  17.         openNotification.addClass('show').addClass('open--rot');
  18.         setTimeout(function () {
  19.             openNotification.addClass('open--width');
  20.         }, 1250);
  21.         setTimeout(function () {
  22.             openNotification.find('.flex-container').addClass('drop-down');
  23.         }, 3000);
  24.         $('body').append('<div class="overlay"></div>');
  25.     }, 50);
  26. }
  27. function closeNotification() {
  28.     var type = $('.notification.open');
  29.     type.find('.drop-down').removeClass('drop-down');
  30.     setTimeout(function () {
  31.         type.removeClass('open--width');
  32.     }, 400);
  33.     setTimeout(function () {
  34.         type.removeClass('open--rot');
  35.     }, 700);
  36.     setTimeout(function () {
  37.         type.removeClass('show');
  38.     }, 900);
  39.     setTimeout(function () {
  40.         $('.overlay').remove();
  41.         type.removeClass('open');
  42.     }, 1000);
  43.     setTimeout(function () {
  44.         type.addClass('notification-hidden');
  45.     }, 1050);
  46. }

微软 Xbox One 样式消息框特效

已有 458 人购买
查看演示升级 VIP立刻购买

演示地址 下载地址
收藏
(0)

发表回复

热销模板

Ashade - 作品展示摄影相册WordPress汉化主题
LensNews

本站承接 WordPress / PbootCMS / DedeCMS 等
系统建站、仿站、开发、定制等业务!