Creating A TV Shutdown Effect with CSS3 Transitions and Transforms

File Size: 2.31 KB
Views Total: 5673
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Creating A TV Shutdown Effect with CSS3 Transitions and Transforms

A nice-looking TV interface with a fancy TV shutdown effect when you click the toggle link, build in jQuery and CSS3 transitions & transforms.

How to use it:

1. Create the Html for a TV screen that you can embed any video into it.

<div class="tv">
  <div class="screen-inner">
    <div class="screen-content">
      <iframe src="//player.vimeo.com/video/25323516?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="590" height="330" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
    </div>
  </div>
  <div class="tv-panel">
    <div class="tv-panel__indicators"> <span></span> <span></span> <span></span> </div>
    <div class="tv-panel__buttons"> <span></span> <span></span> <span></span> <span></span> </div>
  </div>
</div>

2. The sample CSS to style the TV screen.

.tv {
  width: 100%;
  height: 400px;
  margin: 15px 0 0 0;
  position: relative;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  background: #231f20;
  -webkit-box-shadow: 13px 13px rgba(0, 0, 0, 0.16);
  box-shadow: 13px 13px rgba(0, 0, 0, 0.16);
}

.screen-inner {
  width: 590px;
  height: 330px;
  position: absolute;
  top: 15px;
  left: 15px;
  -webkit-box-sizing: border-box;
  -moz-box-sizing: border-box;
  box-sizing: border-box;
  background-color: black;
  overflow: hidden;
}

.screen-content {
  width: 100%;
  height: 100%;
  position: relative;
  -webkit-background-size: cover;
  background-size: cover;
  background-position: center center;
}

.screen-content:after {
  width: 100%;
  height: 100%;
  content: "";
  position: absolute;
  background: white;
  opacity: 0;
  left: 0;
  top: 0;
}

.tv-panel {
  height: 40px;
  width: 100%;
  background: #343434;
  position: absolute;
  bottom: 0;
  left: 0;
}

.tv-panel__indicators {
  position: absolute;
  left: 6px;
  bottom: 5px;
  font-size: 0;
}

.tv-panel__indicators SPAN {
  background: #fa4c4c;
  width: 3px;
  height: 3px;
  margin: 0 4px 0 0;
  border-radius: 100%;
  display: inline-block;
  -webkit-transition: background 150ms ease;
  transition: background 150ms ease;
}

.tv-panel__buttons {
  position: absolute;
  left: 50%;
  margin: 0 0 0 -32px;
  bottom: 16px;
  font-size: 0;
}

.tv-panel__buttons SPAN {
  background: #222222;
  width: 14px;
  height: 7px;
  margin: 0 3px 0 0;
  display: inline-block;
  -webkit-transition: background 150ms ease;
  transition: background 150ms ease;
}

3. Create a link to close the video with a TV shutdown effect.

<a href="#" class="js-shtd-btn">Click me!</a>

4. The required CSS styles for the TV shutdown effect.

.tv._off .screen-content {
  -webkit-animation: shutdown 400ms linear;
  animation: shutdown 400ms linear;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
}

.tv._off .screen-content:after {
  -webkit-animation: shutdown-opa 400ms linear;
  animation: shutdown-opa 400ms linear;
  -webkit-animation-fill-mode: forwards;
  animation-fill-mode: forwards;
}

.tv._off .tv-panel__indicators SPAN { background: #8f8875; }

 @-webkit-keyframes 
shutdown {  0% {
 -webkit-transform: scale3d(1, 1, 1);
 transform: scale3d(1, 1, 1);
}
 20% {
 -webkit-transform: scale3d(1, 1.6, 1);
 transform: scale3d(1, 1.6, 1);
}
 50% {
 -webkit-transform: scale3d(1, 0.005, 1);
 transform: scale3d(1, 0.005, 1);
}
 100% {
 -webkit-transform: scale3d(0, 0, 1);
 transform: scale3d(0, 0, 1);
}
}
 @keyframes 
shutdown {  0% {
 -webkit-transform: scale3d(1, 1, 1);
 transform: scale3d(1, 1, 1);
}
 20% {
 -webkit-transform: scale3d(1, 1.6, 1);
 transform: scale3d(1, 1.6, 1);
}
 50% {
 -webkit-transform: scale3d(1, 0.005, 1);
 transform: scale3d(1, 0.005, 1);
}
 100% {
 -webkit-transform: scale3d(0, 0, 1);
 transform: scale3d(0, 0, 1);
}
}
@-webkit-keyframes 
shutdown-opa {  0% {
 opacity: 0;
}
 50% {
 opacity: 1;
}
 100% {
 opacity: 1;
}
}
@keyframes 
shutdown-opa {  0% {
 opacity: 0;
}
 50% {
 opacity: 1;
}
 100% {
 opacity: 1;
}
}

5. Include the latest version of jQuery library at the bottom of the web page.

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

6. The Javascript to enable the TV shutdown effect when you click the toggle link.

var $tv = $('.tv')
  ,$screen = $('.screen-content')
  ,$btn = $('.js-shtd-btn')
  ,videoHtml = '<iframe src="//player.vimeo.com/video/25323516?title=0&amp;byline=0&amp;portrait=0&amp;autoplay=1" width="590" height="330" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';

$btn.on('click', function(){
  if ($tv.hasClass('_off')) {
    $tv.removeClass('_off');
    $screen.html(videoHtml)
  } else {
    $tv.addClass('_off');
    $screen.empty();
  }
})

This awesome jQuery plugin is developed by edbond88. For more Advanced Usages, please check the demo page or visit the official website.