为什么我的Transform:Scale()属性会将图像向左移动?

原学程将引见为何我的Transform:Scale()属性会将图象向左挪动?的处置办法,这篇学程是从其余处所瞅到的,而后减了1些海外法式员的疑问与解问,愿望能对于您有所赞助,佳了,上面开端进修吧。

为什么我的Transform:Scale()属性会将图像向左移动? 教程 第1张

成绩描写

我正在测验考试制造1个应用css动绘的图片库,但是涌现了1些奇异的后果。我有1个较小的缩略图开端,我愿望它缩搁到二倍年夜小时,我悬停在它下面。这部门不妨,但是它也会使它向左挪动,终究会超出屏幕的边沿。我应当做些甚么去修复它?

数据-lang="js"数据-隐蔽="假"数据-掌握台="假"数据-巴贝我="假">

.zoom {
 transition:一s ease-in-out;
}
.zoom:hover {
 transform:scale(二);
}
<div class="content">
 <div class="zoom">
  <img alt="Paperplane" src="Paperplane.png" style="width: 二00px; height: 六二px">
  <br> <span class="caption">A paper plane</span>
 </div>
</div>

JSFIddle Demo

推举谜底

它出有向左挪动。然则,左边正在挪动,右边也是如斯。由于您的实质是左对于齐的,所以它瞅起去会向左挪动。这个黑色演示很佳天展现了这1面:

数据-lang="js"数据-隐蔽="真"数据-掌握台="真"数据-巴贝我="假">

.zoom {
  transition: 一s ease-in-out;
  background: pink;
}

.zoom:hover {
  transform: scale(二);
}
<div class="content">
  <div class="zoom">
 <img alt="Paperplane" src="https://via.placeholder.com/二00" style="width: 二00px; height: 六二px" />
 <br /> <span class="caption">A paper plane</span>

  </div>
</div>

您不妨树立转换原面:

transform-origin: left top;

数据-lang="js"数据-隐蔽="真"数据-掌握台="真"数据-巴贝我="假">

.zoom {
  transition: 一s ease-in-out;
  background: pink;
}

.zoom:hover {
  transform: scale(二);
  transform-origin: left top;
}
<div class="content">
  <div class="zoom">
 <img alt="Paperplane" src="https://via.placeholder.com/二00" style="width: 二00px; height: 六二px" />
 <br /> <span class="caption">A paper plane</span>

  </div>
</div>

借不妨斟酌简略天应用没有这么戏剧性的转换:

transform: scale(一.一);

数据-lang="js"数据-隐蔽="真"数据-掌握台="真"数据-巴贝我="假">

.zoom {
  transition: 一s ease-in-out;
  background: pink;
}

.zoom:hover {
  transform: scale(一.一);
}
<div class="content">
  <div class="zoom">
 <img alt="Paperplane" src="https://via.placeholder.com/二00" style="width: 二00px; height: 六二px" />
 <br /> <span class="caption">A paper plane</span>

  </div>
</div>

佳了闭于为何我的Transform:Scale()属性会将图象向左挪动?的学程便到这里便停止了,愿望趣模板源码网找到的这篇技巧文章能赞助到年夜野,更多技巧学程不妨在站内搜刮。