缩放图像时避免滞后

发布于 2025-01-31 07:42:01 字数 1788 浏览 0 评论 0原文

我有这个问题,当我使用transform:scale();属性在CSS中进行缩放时,我的图像非常卑鄙。我将图片从0到1缩放。

我的图片缩小了很多尺寸,因此我认为问题可能不会来自这里。

这是一个实际问题的视频: lag image视频

这是html:

<div class="picture-container first-part">
          <div
            class="picture-frame first-part"
            :style="{
              width: pictureFrameWidth + '%',
              height: pictureFrameHeight + 'vh',
            }"
          >
            <img
              src="../assets/pictures/cathedrale.jpg"
              alt="picture of Notre Dame de Reims"
              class="picture top-left"
              id="firstPic"
              :style="{ transform: 'scale(' + pictureScale + ')' }"
            />
          </div>
        </div>

CSS:

.picture-container {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  justify-self: center;
  align-items: center;

  width: 40%;
  height: 100vh;
}
.picture-container.first-part {
  position: sticky;

  top: 0px;
}
.picture-frame {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  align-items: center;

  padding: 5%;

  border: solid 1px var(--color);
}
.picture {
  z-index: 1;
  width: 100%;
  height: 100%;
}

JS:

constrain(n, high, low) {
      return Math.max(Math.min(n, high), low);
    },
resizePicture() {
  this.pictureScale = window.scrollY / 1500 - 0.75;
      let constrainedPictureScale = this.constrain(this.pictureScale, 1, 0);
      this.pictureScale = constrainedPictureScale;
}

我在用户滚动时调用resizePicture()函数。

因此,如果您对如何以不同的方式进行优化或这样做有任何了解,那么我只是不希望这个滞后。

I have this problem, my image is very lagy when i'm scaling it using the transform: scale(); property in CSS. I'm scaling the picture from 0 to 1.

My picture is downsize by a lot so I don't think the problem could come from here.

Here's a video of the actual problem : lag image video

Here is the HTML :

<div class="picture-container first-part">
          <div
            class="picture-frame first-part"
            :style="{
              width: pictureFrameWidth + '%',
              height: pictureFrameHeight + 'vh',
            }"
          >
            <img
              src="../assets/pictures/cathedrale.jpg"
              alt="picture of Notre Dame de Reims"
              class="picture top-left"
              id="firstPic"
              :style="{ transform: 'scale(' + pictureScale + ')' }"
            />
          </div>
        </div>

CSS:

.picture-container {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  justify-self: center;
  align-items: center;

  width: 40%;
  height: 100vh;
}
.picture-container.first-part {
  position: sticky;

  top: 0px;
}
.picture-frame {
  display: flex;
  flex-flow: row nowrap;
  justify-content: center;
  align-items: center;

  padding: 5%;

  border: solid 1px var(--color);
}
.picture {
  z-index: 1;
  width: 100%;
  height: 100%;
}

JS :

constrain(n, high, low) {
      return Math.max(Math.min(n, high), low);
    },
resizePicture() {
  this.pictureScale = window.scrollY / 1500 - 0.75;
      let constrainedPictureScale = this.constrain(this.pictureScale, 1, 0);
      this.pictureScale = constrainedPictureScale;
}

I'm calling the resizePicture() function when the user scroll.

So if you have any idea of how I could optimize this or do it in a different way, I just don't want this lag.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文