CSS转换比例适合窗口大小

问题描述 投票:0回答:1

我已经尝试了很多,但是没有得到适当的解决方案。

这是我的代码:

$(function() {
  $(".zoom-close").on("click", function() {
    $(".zoom-close").toggleClass("transform", 1000);
    $(".img").toggleClass("active", 1000);
  });
});
body {
  background: red;
  width: 100%;
  margin: 0;
}

.col {
  width: 30%;
}

.img {
  display: block;
  transition: all 0.5s ease;
  position: relative;
  transition: all 0.5s ease;
  -webkit-transition: 1s
}

.img img {
  width: 100%;
}

.img.active {
  position: absolute;
  left: 0;
  top: 0;
  transform: scale(2.5);
  -webkit-transform-origin: top left;
  transition: all 0.5s ease;
}

.img.active img {
  transition: all 0.5s ease;
}

.zoom-close {
  position: absolute;
  right: 10px;
  bottom: 10px;
  background: #eee;
  border: 0;
  width: 32px;
  height: 32px;
  padding: 8px 8px 15px;
  cursor: pointer;
  outline: 0;
  border-radius: 0;
  transition: all 0.5s ease;
}

.zoom-close.transform {
  border-radius: 100%;
  transition: all 0.5s ease;
  z-index: 10;
  background: #fff;
  position: absolute;
  right: 5px;
  top: 18px;
}

.zoom-close.transform .zoom-inner {
  opacity: 0;
  transition: all 0.5s ease;
}

.zoom-close.transform .zoom {
  border: 0;
}

.zoom-close.transform .zoom:before {
  width: 2px;
  height: 17px;
  top: 1px;
  left: 7px;
  transform: rotate(45deg);
  transition: all 0.5s ease;
}

.zoom-close.transform .zoom:after {
  height: 2px;
  width: 17px;
  top: 9px;
  left: -1px;
  transform: rotate(45deg);
  transition: all 0.5s ease;
}

.zoom {
  width: 10px;
  height: 10px;
  border-radius: 8px;
  position: relative;
  border: 2px solid #000;
}

.zoom:before {
  content: '';
  width: 2px;
  height: 8px;
  background: #000;
  display: block;
  top: 1px;
  left: 4px;
  position: absolute;
  transition: all 0.5s ease;
}

.zoom-inner {
  width: 8px;
  height: 3px;
  display: block;
  background: #000;
  position: absolute;
  top: 10px;
  left: 7px;
  transform: rotate(45deg);
  -webkit-transform: rotate(45deg);
  transition: all 0.5s ease;
}

.zoom:after {
  content: '';
  height: 2px;
  width: 8px;
  background: #000;
  display: block;
  top: 4px;
  left: 1px;
  position: absolute;
  transition: all 0.5s ease;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="col">
  <div class="img">
    <img src="https://via.placeholder.com/250">
    <button class="zoom-close">
      <div class="zoom"><span class="zoom-inner"></span> </div>
    </button>
  </div>
</div>

在以下情况下有人可以帮助我吗:

当我们单击具有相同变换效果的<div class="img">时,应适合窗口大小(100%宽度)的窗口大小。

((请注意:CSS变换属性不是强制性的,但我需要的是类似的效果。)

javascript jquery html css css-transitions
1个回答
2
投票

您需要获得<button class="zoom-close">事件上的屏幕尺寸,例如widthheight

HTML

zoom

JS

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<div class="col">
  <div class="img">
    <img src="https://via.placeholder.com/250"  >

  </div>
    <br><br><br>
    <button class="zoom-close">
      <div class="zoom"><span class="zoom-inner"></span> </div>
    </button>
</div>
© www.soinside.com 2019 - 2024. All rights reserved.