简体   繁体   English

如何显示带有动画的溢出文本?(Javascript-HTML-CSS)

[英]How to show overflowing text with animation?(Javascript - HTML - CSS)

Is there any way of recognizing text overflow with JS and show the overflowing text in an animated way ? 有没有办法用JS识别文本溢出以动画方式显示溢出文本 For example, moving the text to the left, like the spotify widget: 例如,将文本移到左侧,例如spotify小部件:

Spotify Web小部件

You should be able to confirm a text requires scrolling if you use "scrollWidth > clientWidth " of the container - assuming it has overflow:hidden and you take margin, padding and borders into account. 如果您使用容器的“ scrollWidth> clientWidth”,则应该能够确认需要滚动的文本-假设其已溢出:隐藏,并且考虑了边距,边距和边框。 Look at element dimensions for a basic overview. 查看元素尺寸以获得基本概述。 To scroll the text you just have to give it a negative margin-left, or use a DIV with position:absolute inside a DIV with position:relative and give the inner one a negative left value (CSS). 要滚动文本,您只需要给其负的左边距,或在具有position:relative的DIV中使用具有position:absolute的DIV,并为内部的文本提供一个负的left值(CSS)。

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

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