zero_shubham1

weird-transitionend.html

Dec 7th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.98 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.   <meta charset="UTF-8">
  5.   <title>Flex Panels 💪</title>
  6.   <link href='https://fonts.googleapis.com/css?family=Amatic+SC' rel='stylesheet' type='text/css'>
  7. </head>
  8. <body>
  9.   <style>
  10.     html {
  11.       box-sizing: border-box;
  12.       background: #ffc600;
  13.       font-family: 'helvetica neue';
  14.       font-size: 20px;
  15.       font-weight: 200;
  16.     }
  17.    
  18.     body {
  19.       margin: 0;
  20.     }
  21.    
  22.     *, *:before, *:after {
  23.       box-sizing: inherit;
  24.     }
  25.  
  26.     .panels {
  27.       min-height: 100vh;
  28.       overflow: hidden;
  29.  
  30.       display: flex;
  31.      
  32.     }
  33.  
  34.     .panel {
  35.       background: #6B0F9C;
  36.       box-shadow: inset 0 0 0 5px rgba(255,255,255,0.1);
  37.       color: white;
  38.       text-align: center;
  39.       align-items: center;
  40.       /* Safari transitionend event.propertyName === flex */
  41.       /* Chrome + FF transitionend event.propertyName === flex-grow */
  42.       transition:
  43.         font-size 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
  44.         flex 0.7s cubic-bezier(0.61,-0.19, 0.7,-0.11),
  45.         background 0.2s;
  46.       font-size: 20px;
  47.       background-size: cover;
  48.       background-position: center;
  49.  
  50.       flex: 1;
  51.      
  52.       display: flex;
  53.       flex-direction: column;
  54.       align-items: center;
  55.       justify-content: space-around;
  56.  
  57.     }
  58.  
  59.     .panel1 { background-image:url(https://source.unsplash.com/gYl-UtwNg_I/1500x1500); }
  60.     .panel2 { background-image:url(https://source.unsplash.com/rFKUFzjPYiQ/1500x1500); }
  61.     .panel3 { background-image:url(https://images.unsplash.com/photo-1465188162913-8fb5709d6d57?ixlib=rb-0.3.5&q=80&fm=jpg&crop=faces&cs=tinysrgb&w=1500&h=1500&fit=crop&s=967e8a713a4e395260793fc8c802901d); }
  62.     .panel4 { background-image:url(https://source.unsplash.com/ITjiVXcwVng/1500x1500); }
  63.     .panel5 { background-image:url(https://source.unsplash.com/3MNzGlQM7qs/1500x1500); }
  64.  
  65.     /* Flex Children */
  66.     .panel > * {
  67.       margin: 0;
  68.       width: 100%;
  69.       transition: transform 0.5s;
  70.     }
  71.  
  72.     .panel > *:first-child{
  73.       transform: translateY(-1000%);
  74.     }
  75.    
  76.     .panel.openActive > *:first-child{
  77.       transform: translateY(0);
  78.     }
  79.  
  80.     .panel > *:last-child{
  81.       transform: translateY(1000%);
  82.     }
  83.  
  84.     .panel.openActive > *:last-child{
  85.       transform: translateY(0);
  86.     }
  87.  
  88.     .panel p {
  89.       text-transform: uppercase;
  90.       font-family: 'Amatic SC', cursive;
  91.       text-shadow: 0 0 4px rgba(0, 0, 0, 0.72), 0 0 14px rgba(0, 0, 0, 0.45);
  92.       font-size: 2em;
  93.     }
  94.    
  95.     .panel p:nth-child(2) {
  96.       font-size: 4em;
  97.     }
  98.  
  99.     .panel.open {
  100.       font-size: 40px;
  101.       flex: 4;
  102.     }
  103.  
  104.   </style>
  105.  
  106.  
  107.   <div class="panels">
  108.     <div class="panel panel1">
  109.       <p>Hey</p>
  110.       <p>Let's</p>
  111.       <p>Dance</p>
  112.     </div>
  113.     <div class="panel panel2">
  114.       <p>Give</p>
  115.       <p>Take</p>
  116.       <p>Receive</p>
  117.     </div>
  118.     <div class="panel panel3">
  119.       <p>Experience</p>
  120.       <p>It</p>
  121.       <p>Today</p>
  122.     </div>
  123.     <div class="panel panel4">
  124.       <p>Give</p>
  125.       <p>All</p>
  126.       <p>You can</p>
  127.     </div>
  128.     <div class="panel panel5">
  129.       <p>Life</p>
  130.       <p>In</p>
  131.       <p>Motion</p>
  132.     </div>
  133.   </div>
  134.  
  135.   <script>
  136.     var panelList = document.querySelectorAll(".panel");
  137.     var lastActive = '';
  138.     function closeOpen(){
  139.       if(!lastActive)
  140.         return;
  141.       var lastPanel = document.querySelector(`.${lastActive}`);
  142.       lastPanel.classList.toggle('open',false);
  143.       lastPanel.classList.toggle('openActive',false);
  144.     };
  145.  
  146.     function openActive(e){
  147.       this.classList.toggle('open',true);
  148.       closeOpen();
  149.       lastActive = this.classList[1];
  150.     }
  151.  
  152.     function flexGrow(e){
  153.       if(e.propertyName.includes('flex')){
  154.         this.classList.toggle('openActive',true);
  155.       }
  156.      
  157.     }
  158.  
  159.     panelList.forEach(el => {
  160.       el.addEventListener('click',openActive);
  161.       el.addEventListener('transitionend',flexGrow);
  162.      
  163.     });
  164.   </script>
  165.  
  166.  
  167.  
  168. </body>
  169. </html>
Add Comment
Please, Sign In to add comment