简体   繁体   English

如何使此列表项“缩放”

[英]How to make this list item “zoom”

I am trying to make list items "zoom" when selected. 我正在尝试使列表项在选中时“缩放”。 I'm having trouble finding the best way to make this happen. 我很难找到实现这一目标的最佳方法。 I'm using GSAP and the javascript is working just fine, but I'm having a hard time finding which property would best achieve the desired "zoom" effect. 我正在使用GSAP,而javascript正常工作,但是我很难找到哪个属性最能达到所需的“缩放”效果。

https://jsfiddle.net/Leahp374/1/ https://jsfiddle.net/Leahp374/1/

At the moment, I am attempting to use CSS perspective and translate3d to move the item closer in the Z direction. 目前,我正在尝试使用CSS perspectivetranslate3d将项目沿Z方向移近。 However, since the perspective-origin is at 50% 50% , and since the list item is centered in its parent container, the first and last list items move towards the top and bottom, respectively. 但是,由于perspective-origin位于50% 50% ,并且由于列表项位于其父容器的中心,因此第一个和最后一个列表项分别移向顶部和底部。 Instead, I'd like them to all behave as the middle list item. 相反,我希望它们都充当中间列表项。

Using something like font-size will cause the element to 're-center' based on it's new width, which is not desirable. 使用诸如font-size内容会使元素根据其新宽度“重新居中”,这是不希望的。

What is the best way to achieve the "zoom" effect? 实现“缩放”效果的最佳方法是什么?

Is this the desired 'zoom' effect that you are looking for? 这是您想要的“缩放”效果吗? You can use scale transform along with transform origin to get the desired zoom effect. 您可以将缩放变换与变换原点一起使用以获得所需的缩放效果。

 html, body { height: 100%; } div { perspective: 600px; width: 100%; height: 100%; background: red; display: flex; flex-direction: row; align-items: center; justify-content: center; } li:nth-child(1) { transform: scale(1.5); transform-origin:-40%; } 
 <div> <ul> <li>One</li> <li>Two</li> <li>Three</li> </ul> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM