[英]CSS How to calculate the translateX value of "width: max-content"?
How should I calculate the translateX()
value when using width: max-content
?使用
width: max-content
时应该如何计算translateX()
值? I want the text to fully scroll out of the container.我希望文本完全滚出容器。
@keyframes scroll_text {
0% {
transform: translateX(0)
}
100% {
transform: translateX(??)
}
}
div.container {
margin: 2rem;
padding-block: 1em
background-color: black
overflow: hidden
}
div.container p {
line-height: 1em
width: max-content
position: relative
left: 100%
animation: scroll_text 15s linear infinite
}
This is what ended up working for me (via Typescript).这就是最终为我工作的(通过 Typescript)。 Thank you @Paulie_D.
谢谢@Paulie_D。
let scroll_container: HTMLDivElement | undefined
let scroll_text: HTMLParagraphElement | undefined
const width = {
container: (scroll_container as HTMLDivElement).clientWidth,
text: (scroll_text as HTMLParagraphElement).offsetWidth,
}
document.documentElement.style.setProperty(
'--scroll-text-width',
(width.container + width.text) * -1 + 'px'
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.