简体   繁体   English

在insertBefore之后,CSS Transition不会触发

[英]CSS Transition is not triggering after insertBefore

I am trying to create an horizontal carousel that loops. 我正在尝试创建一个循环的水平旋转木马。

You can check the code here: https://codepen.io/nobitta/pen/xNOyrj 您可以在此处查看代码: https//codepen.io/nobitta/pen/xNOyrj

At the moment I am stuck. 此刻我被困住了。 I managed to make it work, however the CSS transition that mimics the movement to the right, is not triggering when you click "next". 我设法让它工作,但是当你点击“下一步”时,模拟向右移动的CSS过渡不会触发。

I already did some research and some say this has to do with browsers optimization and that setting a timeout or calling offsetWidth or getBoundingRect() should do the trick, as it forces the browser to re-render. 我已经做了一些研究,有人说这与浏览器优化有关,设置超时或调用offsetWidthgetBoundingRect()应该可以解决问题,因为它会强制浏览器重新渲染。 However, even with those tips, I was not able to make it work... 然而,即使有这些提示,我也无法使其发挥作用......

Am I doing something wrong or missing something here? 我做错了什么或错过了什么吗? What should I do? 我该怎么办?

Thanks in advance ~ 提前谢谢〜

I managed to fix it by playing around with the margin-left property. 我设法通过玩左边缘属性来修复它。

My bet is that when I prepended the last slider's item, it naturally shifted right due to the new element's size and the space it occupies. 我敢打赌,当我添加最后一个滑块的项目时,由于新元素的大小和占据的空间,它自然向右移动。 Therefore I decided to shift it back to mask the insertion shift. 因此我决定将其移回以掩盖插入移位。 I followed the same reasoning for the appended items. 我对附加项目采用了相同的推理。

You can check the codepen in the question for more detail. 您可以查看问题中的codepen以获取更多详细信息。

I hope this helps someone. 我希望这可以帮助别人。

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

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