简体   繁体   English

自动换行垂直滑动文本动画

[英]Word-Wrap Vertical Sliding Text Animation

My vertical sliding text animation keeps getting cut off under mobile width.我的垂直滑动文本动画在移动宽度下不断被切断。 I've been trying to use media queries to target the code but I couldn't get the text and animation to wrap together.我一直在尝试使用媒体查询来定位代码,但我无法将文本和动画包装在一起。 How do I adjust my code in order to have the entire animation and text wrap to a reduced width?如何调整我的代码以使整个动画和文本换行到减小的宽度? Thanks!谢谢!

Here's the HTML & CSS code I'm currently using.这是我目前使用的 HTML 和 CSS 代码。

 /*Sentence*/ .sentence { color: #222; font-size: 55px; text-align: left; } /*Wrapper*/ .wrapper { background-color: ; font-family: 'Cabin', sans-serif; margin: 50px auto; padding: 0px 0px; position: relative; width: 100%; } /*Vertical Sliding*/ .slidingVertical { display: inline; text-indent: 14px; } .slidingVertical span { animation: topToBottom 12.5s linear infinite 0s; -ms-animation: topToBottom 12.5s linear infinite 0s; -webkit-animation: topToBottom 12.5s linear infinite 0s; color: #00abe9; opacity: 0; overflow: hidden; position: absolute; } .slidingVertical span:nth-child(2) { animation-delay: 2.5s; -ms-animation-delay: 2.5s; -webkit-animation-delay: 2.5s; } .slidingVertical span:nth-child(3) { animation-delay: 5s; -ms-animation-delay: 5s; -webkit-animation-delay: 5s; } .slidingVertical span:nth-child(4) { animation-delay: 7.5s; -ms-animation-delay: 7.5s; -webkit-animation-delay: 7.5s; } .slidingVertical span:nth-child(5) { animation-delay: 10s; -ms-animation-delay: 10s; -webkit-animation-delay: 10s; } /*topToBottom Animation*/ @-moz-keyframes topToBottom { 0% { opacity: 0; } 5% { opacity: 0; -moz-transform: translateY(-50px); } 10% { opacity: 1; -moz-transform: translateY(0px); } 25% { opacity: 1; -moz-transform: translateY(0px); } 30% { opacity: 0; -moz-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-webkit-keyframes topToBottom { 0% { opacity: 0; } 5% { opacity: 0; -webkit-transform: translateY(-50px); } 10% { opacity: 1; -webkit-transform: translateY(0px); } 25% { opacity: 1; -webkit-transform: translateY(0px); } 30% { opacity: 0; -webkit-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes topToBottom { 0% { opacity: 0; } 5% { opacity: 0; -ms-transform: translateY(-50px); } 10% { opacity: 1; -ms-transform: translateY(0px); } 25% { opacity: 1; -ms-transform: translateY(0px); } 30% { opacity: 0; -ms-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } /*Vertical Flip*/ .verticalFlip { display: inline; text-indent: 14px; } .verticalFlip span { animation: vertical 12.5s linear infinite 0s; -ms-animation: vertical 12.5s linear infinite 0s; -webkit-animation: vertical 12.5s linear infinite 0s; color: #00abe9; opacity: 0; overflow: hidden; position: absolute; } .verticalFlip span:nth-child(2) { animation-delay: 2.5s; -ms-animation-delay: 2.5s; -webkit-animation-delay: 2.5s; } .verticalFlip span:nth-child(3) { animation-delay: 5s; -ms-animation-delay: 5s; -webkit-animation-delay: 5s; } .verticalFlip span:nth-child(4) { animation-delay: 7.5s; -ms-animation-delay: 7.5s; -webkit-animation-delay: 7.5s; } .verticalFlip span:nth-child(5) { animation-delay: 10s; -ms-animation-delay: 10s; -webkit-animation-delay: 10s; } /*Vertical Flip Animation*/ @-moz-keyframes vertical { 0% { opacity: 0; } 5% { opacity: 0; -moz-transform: rotateX(180deg); } 10% { opacity: 1; -moz-transform: translateY(0px); } 25% { opacity: 1; -moz-transform: translateY(0px); } 30% { opacity: 0; -moz-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-webkit-keyframes vertical { 0% { opacity: 0; } 5% { opacity: 0; -webkit-transform: rotateX(180deg); } 10% { opacity: 1; -webkit-transform: translateY(0px); } 25% { opacity: 1; -webkit-transform: translateY(0px); } 30% { opacity: 0; -webkit-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes vertical { 0% { opacity: 0; } 5% { opacity: 0; -ms-transform: rotateX(180deg); } 10% { opacity: 1; -ms-transform: translateY(0px); } 25% { opacity: 1; -ms-transform: translateY(0px); } 30% { opacity: 0; -ms-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0; } }
 <section class="wrapper"> <h2 class="sentence">A Global Leader in <div class="slidingVertical"> <span>3PL</span> <span>Trading</span> <span>Manufacturing</span> <span>Warehousing</span> <span>Distribution</span> </div> </h2> </section>

Try like this:像这样尝试:

 /*Sentence*/ .sentence{ color: #222; font-size: 55px; text-align: left; display: block; } .sentence > span { display: inline-block; margin-right: 14px; margin-bottom:0.5em; } /*Wrapper*/ .wrapper{ background-color: ; font-family: 'Cabin', sans-serif; margin: 100px auto; padding: 0px 0px; position: relative; width: 100%; } /*Vertical Sliding*/ .slidingVertical{ display: inline-block; width:7em; height:1.2em; vertical-align: top; } .slidingVertical span{ animation: topToBottom 12.5s linear infinite 0s; -ms-animation: topToBottom 12.5s linear infinite 0s; -webkit-animation: topToBottom 12.5s linear infinite 0s; color: #00abe9; opacity: 0; overflow: hidden; position: absolute; } .slidingVertical span:nth-child(2){ animation-delay: 2.5s; -ms-animation-delay: 2.5s; -webkit-animation-delay: 2.5s; } .slidingVertical span:nth-child(3){ animation-delay: 5s; -ms-animation-delay: 5s; -webkit-animation-delay: 5s; } .slidingVertical span:nth-child(4){ animation-delay: 7.5s; -ms-animation-delay: 7.5s; -webkit-animation-delay: 7.5s; } .slidingVertical span:nth-child(5){ animation-delay: 10s; -ms-animation-delay: 10s; -webkit-animation-delay: 10s; } /*topToBottom Animation*/ @-moz-keyframes topToBottom{ 0% { opacity: 0; } 5% { opacity: 0; -moz-transform: translateY(-50px); } 10% { opacity: 1; -moz-transform: translateY(0px); } 25% { opacity: 1; -moz-transform: translateY(0px); } 30% { opacity: 0; -moz-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-webkit-keyframes topToBottom{ 0% { opacity: 0; } 5% { opacity: 0; -webkit-transform: translateY(-50px); } 10% { opacity: 1; -webkit-transform: translateY(0px); } 25% { opacity: 1; -webkit-transform: translateY(0px); } 30% { opacity: 0; -webkit-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes topToBottom{ 0% { opacity: 0; } 5% { opacity: 0; -ms-transform: translateY(-50px); } 10% { opacity: 1; -ms-transform: translateY(0px); } 25% { opacity: 1; -ms-transform: translateY(0px); } 30% { opacity: 0; -ms-transform: translateY(50px); } 80% { opacity: 0; } 100% { opacity: 0; } } /*Vertical Flip*/ .verticalFlip{ display: inline; text-indent: 14px; } .verticalFlip span{ animation: vertical 12.5s linear infinite 0s; -ms-animation: vertical 12.5s linear infinite 0s; -webkit-animation: vertical 12.5s linear infinite 0s; color: #00abe9; opacity: 0; overflow: hidden; position: absolute; } .verticalFlip span:nth-child(2){ animation-delay: 2.5s; -ms-animation-delay: 2.5s; -webkit-animation-delay: 2.5s; } .verticalFlip span:nth-child(3){ animation-delay: 5s; -ms-animation-delay: 5s; -webkit-animation-delay: 5s; } .verticalFlip span:nth-child(4){ animation-delay: 7.5s; -ms-animation-delay: 7.5s; -webkit-animation-delay: 7.5s; } .verticalFlip span:nth-child(5){ animation-delay: 10s; -ms-animation-delay: 10s; -webkit-animation-delay: 10s; } /*Vertical Flip Animation*/ @-moz-keyframes vertical{ 0% { opacity: 0; } 5% { opacity: 0; -moz-transform: rotateX(180deg); } 10% { opacity: 1; -moz-transform: translateY(0px); } 25% { opacity: 1; -moz-transform: translateY(0px); } 30% { opacity: 0; -moz-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0;} } @-webkit-keyframes vertical{ 0% { opacity: 0; } 5% { opacity: 0; -webkit-transform: rotateX(180deg); } 10% { opacity: 1; -webkit-transform: translateY(0px); } 25% { opacity: 1; -webkit-transform: translateY(0px); } 30% { opacity: 0; -webkit-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0; } } @-ms-keyframes vertical{ 0% { opacity: 0; } 5% { opacity: 0; -ms-transform: rotateX(180deg); } 10% { opacity: 1; -ms-transform: translateY(0px); } 25% { opacity: 1; -ms-transform: translateY(0px); } 30% { opacity: 0; -ms-transform: translateY(0px); } 80% { opacity: 0; } 100% { opacity: 0; } }
 <section class="wrapper"> <h2 class="sentence"> <span>A Global Leader in </span> <div class="slidingVertical"> <span> 3PL</span> <span> Trading</span> <span> Manufacturing</span> <span> Warehousing</span> <span> Distribution</span> </div> </h2>

The reason it didn't wrap to the width of the screen was because .slidingVertical span used absolute positioning, so the container .slidingVertical had 0 width.它没有环绕屏幕宽度的原因是因为.slidingVertical span使用了absolute定位,所以容器.slidingVertical宽度为 0。

In the above example, .slidingVertical has been changed to be an inline-block as wide as the widest span inside it (set manually).在上面的示例中, .slidingVertical已更改为与其中最宽跨度一样宽的行inline-block (手动设置)。 This allows the sentence to wrap correctly.这允许句子正确换行。

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

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