Создайте 3D-слайдер с css html - PullRequest
0 голосов
/ 31 января 2020

Я пытаюсь создать слайдер следующим образом:

Img

У слайдера 2 слоя: изображение и холст. При перемещении мыши он создает несколько пузырьков, а затем показывает изображение в слое 1

ссылка

Я думаю, что это можно сделать путем увеличения или уменьшения прозрачности холста слой, но я не знаю, как уменьшить прозрачность только одной части этого слоя.

$(document).ready(function() {
  var mousePos = {};

  function getRandomInt(min, max) {
    return Math.round(Math.random() * (max - min + 1)) + min;
  }

  $(window).mousemove(function(e) {
    mousePos.x = e.pageX;
    mousePos.y = e.pageY;
  });

  $(window).mouseleave(function(e) {
    mousePos.x = -1;
    mousePos.y = -1;
  });

  var draw = setInterval(function() {
    if (mousePos.x > 0 && mousePos.y > 0) {
      var range = 15;
      var color = "background: rgba(0,0,0,.1);";
      var zindex = "z-index:1;";
      var opacity = "opacity : 0 ;"
      var sizeInt = getRandomInt(100, 300);
      size = "height: " + sizeInt + "px; width: " + sizeInt + "px;";
      var left = "left: " + getRandomInt(mousePos.x - range - sizeInt, mousePos.x + range) + "px;";
      var top = "top: " + getRandomInt(mousePos.y - range - sizeInt, mousePos.y + range) + "px;";
      var style = left + top + color + size;

      $("<div><div class='ball' style='" + style + "'></div></div>").appendTo('#wrap').one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function() {
        $(this).remove();
      });
      // $('#wrap').css('opacity', ' 0.6');
    }
  }, 150);
});
@import url(https://fonts.googleapis.com/css?family=Open+Sans);
html,
body {
  margin: 0;
  font-family: "Open Sans";
}

.bg {
  height: 100vh;
  margin: 0;
  padding: 0;
  position: relative;
  background: url('https://img.rawpixel.com/s3fs-private/rawpixel_images/website_content/rm28-colorswirl-aom-271_2.jpg?auto=format&bg=transparent&con=3&cs=srgb&dpr=1&fm=jpg&ixlib=php-3.1.0&mark=rawpixel-watermark.png&markalpha=90&markpad=13&markscale=10&markx=25&q=75&usm=15&vib=3&w=1200&s=d5c44f3d150e4ed1e308e02c447741e0') no-repeat center center / cover;
  z-index: 1;
}

#wrap p {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translateX(-50%) translateY(-50%);
  color: rgba(255, 255, 255, .5);
  font-size: 30px;
  text-transform: uppercase;
  letter-spacing: 5px;
  text-align: center;
}

#wrap {
  width: 100%;
  height: 100%;
  position: relative;
  overflow: hidden;
  background: rgba(245, 245, 245);
  z-index: 5;
}

.ball {
  pointer-events: none;
  position: absolute;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  background: transparent;
  animation: implode 1s ease-in-out;
  animation-fill-mode: both;
}

@keyframes implode {
  100% {
    transform: scale(0)
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="bg">
  <div id="wrap">
    <p>move the cursor around the screen</p>
  </div>
</div>
...