JSFiddle - React, Tailwind, and code Playground

by neverov12

HTML

<div class="effect">
  <img src="https://placeimg.com/640/480/nature" />
  <button>
    See cool effect
  </button>
</div>

<div class="effect">
  <img src="https://placeimg.com/640/480/tech" />
  <button>
    See cool effect
  </button>
</div>

CSS

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.effect {
  position: relative;
  display: inline-block;
  max-width: 640px;
}

.effect-dup {
  filter: grayscale(100%);
  position: absolute;
  overflow: hidden;
  top: 0;
  right: 0;
  direction: rtl;
  width: 100%;
  transition: width 1s ease-in-out;
}

.effect-dup.cool-effect {
  width: 0%;
}

JavaScript

$(".effect img").each(function() {
  $this = $(this);
  imgS = $this.attr("src");

  $this.after("<div class='effect-dup'><img src='" + imgS + "' /></div>")
});

$("button").click(function() {
  $this = $(this);

  $(this).prev().addClass("cool-effect");
})