Smoke mask sprite

In this example below you will see how to do a Smoke mask sprite with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by maximebonhomme, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright maximebonhomme ©

Technologies

  • HTML
  • CSS
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Smoke mask sprite</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  <div class="card">
  <div class="card-nav">
    <a 
       data-link-index="0" 
       class="card-nav__item active" 
       href="#">
        Mocha
    </a>
    <a 
       data-link-index="1" 
       class="card-nav__item" 
       href="#">
        Black Cherry
    </a>
    <a 
       data-link-index="2" 
       class="card-nav__item" 
       href="#">
        Manilla
    </a>
  </div>
  <div class="card-images">
    <div 
         data-image-index="0" 
         class="card-images__item active"
         style="background-image: url(http://bonhomme.lol/_codepen/mocha.jpg);">
    </div>
    <div 
         data-image-index="1" 
         class="card-images__item" 
         style="background-image: url(http://bonhomme.lol/_codepen/cherry.jpg);">
    </div>
    <div 
         data-image-index="2" 
         class="card-images__item" 
         style="background-image: url(http://bonhomme.lol/_codepen/manilla.jpg);">
    </div>
  </div>
</div>
  <script src='https://code.jquery.com/jquery-2.2.4.min.js'></script>

  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/maximebonhomme/smoke-mask-sprite-RaXRKy */
body {
  position: relative;
  background-color: #121413;
  color: #e4e2d8;
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Times', serif;
}

a,
a:visited,
a:focus {
  color: white;
  text-decoration: none;
}

.card {
  width: 100%;
  max-width: 600px;
  height: 90vh;
  max-height: 700px;
  position: relative;
}

.card-nav {
  position: absolute;
  z-index: 50;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.card-nav__item {
  font-size: 50px;
  margin: 20px 0;
  opacity: 0.5;
  transition: 0.25s;
}
.card-nav__item:hover, .card-nav__item.active {
  opacity: 1;
}

.card-images,
.card-images__item,
.card-images__mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.card-images__item {
  z-index: 20;
  background-position: center;
  background-size: cover;
  -webkit-mask-image: url(http://bonhomme.lol/_codepen/mask.png);
  -webkit-mask-size: 1500% 100%;
}
.card-images__item.active {
  -webkit-mask-position: 100% 0;
}
.card-images__item.activate {
  z-index: 30;
  animation: mask 0.5s steps(14) 0s both;
}

@keyframes mask {
  from {
    -webkit-mask-position: 0 0;
  }
  to {
    -webkit-mask-position: 100% 0;
  }
}


/*Downloaded from https://www.codeseek.co/maximebonhomme/smoke-mask-sprite-RaXRKy */
var $imageHolder        = $('.card-images');
var $images             = $imageHolder.find('.card-images__item');
var $linksHolder        = $('.card-nav');
var $links              = $linksHolder.find('.card-nav__item');
var inProgress          = false;

$links.on('click', function(e) {
  e.preventDefault();

  var $this = $(this);
  var index = $this.data('link-index');
  var $image = $('[data-image-index="'+ index +'"]');

  if($image.hasClass('active') || inProgress) return;

  inProgress = true;
  $links.removeClass('active');
  $this.addClass('active');

  $image
    .addClass('activate')
    .on('animationend', function() {
      $images.removeClass('active activate');
      $(this).addClass('active');
      inProgress = false;
    })
  ;
});

Comments