What is the name of this effect?

Asked

Viewed 148 times

-2

I would like to know the name of this effect.

Where has ALL, IDENTITY, LOGO and PRINT. By clicking on each item, the images are separated by categories.

Click here to access

  • It looks like animations,(Animation) that was inserted into the element, look at this: https://daneden.github.io/animate.css/ , you can also inspect the element and see what’s happening there..

  • It has slideUps, fadein’s, Scale... but predominantly fadein’s.

  • 1

    probably the https://mixitup.kunkalabs.com plugin/

  • 2

    @Sanction the plugin used is http://isotope.metafizzy.co/ da to see in the source code...

  • Both bring the same result. Isotope seems to be more complete, with different "separation" options in different categories.

  • Thanks for the suggestions.

Show 1 more comment

1 answer

2


you can achieve this effect using different combinations of Transform, Transition and Animation.

below follows a complete example:

var content = document.getElementById("container");
var content = document.getElementById("content");
var buttons = document.querySelectorAll("#menu input[data-color]");

var random = function (min, max) {
  return Math.floor(Math.random() * max) + min;
}

var width = 240;
var boxes = [];
var cores = ["teal", "indigo", "deep-orange", "blue-gray"];
for (var indice = 0; indice < 36; indice++) {
  var cor = cores[indice % 4];
  var box = document.createElement("div");
  box.classList.add("box");
  box.classList.add(cor);
  box.style.width = (width - 10) + "px";
  box.style.height = random(120, 180) + "px";
  content.appendChild(box);
  boxes.push(box);
}

var currentWidth = 0;
var onWindowResize = function (force) {
  var newWidth = window.innerWidth - window.innerWidth % width;
  if (currentWidth != newWidth || force) {
    content.style.width = newWidth + "px";
    currentWidth = newWidth;

    var colunas = [];
    var limite = currentWidth / width;
    for (var indice = 0; indice < limite; indice++) {
      colunas.push(0);
    } 

    boxes.forEach(function (box, indice) {
      if (!box.classList.contains("hide")) {
        var minimo = Math.min.apply(null, colunas);
        var indice = colunas.indexOf(minimo);
        console.log(box.offsetHeight);
        box.style.top = colunas[indice] + "px";
        box.style.left = (width * indice) + "px";      
        colunas[indice] += box.offsetHeight + 10;
      }
    });

    console.log(colunas);
  }	
}

var onColorClick = function (event) {
  var cor = event.target.dataset.color;
  var todos = !cor;
  boxes.forEach(function (box, indice) {
    if (!todos && !box.classList.contains(cor)) {
      box.classList.remove("show");
      box.classList.add("hide");
    } else if (box.classList.contains("hide")) {
      box.classList.remove("hide");
      box.classList.add("show");
    }    
  });
  onWindowResize(true);
}

window.addEventListener("resize", function () {
  onWindowResize(false);
});

[].forEach.call(buttons, function (button, indice) {
  button.addEventListener("click", onColorClick);	
});

onWindowResize(false);
html, body {
  overflow: auto;
}

#menu {
  position: fixed;
  top: 0px;
  left: 0px;
  right: 0px;
  height: 40px;
  padding: 10px;
  text-align:center;
  background-color: gainsboro;
  box-shadow: 0px 0px 10px black;
  box-sizing: border-box;
}

#container {
  position: fixed;
  overflow: auto;
  top: 40px;
}

#content {
  position: absolute;
  top: 0px;
}

#container, #content {
  left: 0px;
  bottom: 0px;
  right: 0px;
  margin: auto;
}

.box {
  position: absolute;
  border-radius: 5px;
  box-shadow: 0px 0px 5px black;
  margin: 5px;
  transition-property: top, left;
  transition-duration: 0.5s;
  transition-timing-function: linear;  
  
  -webkit-transition-property: top, left;
  -webkit-transition-duration: 0.5s;
  -webkit-transition-timing-function: linear;  
}

.hide {
  animation: hide 0.5s linear;
  animation-fill-mode: forwards;
  
  -webkit-animation: hide 0.5s linear;
  -webkit-animation-fill-mode: forwards;
}

.show {
  animation: hide 0.5s linear;
  animation-fill-mode: forwards;
  
  -webkit-animation: show 0.5s linear;
  -webkit-animation-fill-mode: forwards;
}

@keyframes hide {
  0% { transform: scale(1); }
  100% { transform: scale(0); }
}

@keyframes show {
  0% { transform: scale(0); }
  100% { transform: scale(1); }
}

@-webkit-keyframes hide {
  0% { -webkit-transform: scale(1); }
  100% { -webkit-transform: scale(0); }
}

@-webkit-keyframes show {
  0% { -webkit-transform: scale(0); }
  100% { -webkit-transform: scale(1); }
}

.teal {
  background-color: #009688
}

.indigo {
  background-color: #3F51B5
}

.deep-orange {
  background-color: #FF5722
}

.blue-gray {
  background-color: #607D8B
}
<div id="menu">
  <input type="button" data-color="" value="Todas" />
  <input type="button" data-color="teal" value="Teal" />
  <input type="button" data-color="indigo" value="Indigo" />
  <input type="button" data-color="deep-orange" value="Deep Orange" />
  <input type="button" data-color="blue-gray" value="Blue Gray" />
</div>
<div id="container">
  <div id="content">

  </div>
</div>

to make the "boxes" decrease until they disappear, I used a animation combined with a transform: scale(n).

to move the "boxes", I used a transition and set up the top and left in hand.

as bonus also made the example Responsive, so try to increase and decrease the size of your browser window.

  • Let’s say I always want to change content. Once put colors, again images, again video or whatever.. If the creation of Divs were in the <body>, wouldn’t it be "better" at code maintenance level? Or it varies according to the taste of each dev?

  • @Zkk, on the content, in the example above div.box is just a wrapper for the content, it can contain whatever thing, videos, texts, images, etc... what should be respected is the width, since we are working with a vestical grid.

  • @Zkk, as for using the <body>, understand that the container can be whatever element, section, div, body, etc... then you can put your gallery inside whatever element... as far as code maintenance, I believe it is just the opposite, delimiting a scope for the script will help prevent the appearance of bugs, as well as make them more localized and facilitate their identification...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.