<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>纯css实现文字循环滚动效果</title> <style type="text/css"> * { margin: 0; padding: 0; } .box { width: 300px; margin: 0 auto; border: 1px solid #ff6700; overflow: hidden; } .animate { padding-left: 20px; font-size: 12px; color: #000; display: inline-block; white-space: nowrap; animation: 10s wordsLoop linear infinite normal; } @keyframes wordsLoop { 0% { transform: translateX(250px); -webkit-transform: translateX(250px); } 100% { transform: translateX(-100%); -webkit-transform: translateX(-100%); } } @-webkit-keyframes wordsLoop { 0% { transform: translateX(250px); -webkit-transform: translateX(250px); } 100% { transform: translateX(-100%); -webkit-transform: translateX(-100%); } } </style> </head> <body> <div class="box"> <div class="animate"> 1文字滚动的内容文字滚动 2的内容文字滚动的内容文字滚动的内 3容文字滚动的内容文字滚动的内容文 4字滚动的内容文字滚动的内容文字滚动的内容 </div> </div> </body> </html>
2. element ui table表格中滚动字
<el-table-column prop="line" align="center" label="航线" min-width="520"> <template slot-scope="scope"> <div class="scrollText"> <div class="st-inner" :class="{'st-scrolling': scope.row.line.length>50?true:false}"> <span class="st-section comment">{{scope.row.line}}</span> </div> </div> </template> </el-table-column>
/* 单元格内滚动字 */
.scrollText {
overflow: hidden;
white-space: nowrap;
/* 300px; */
}
.st-inner {
display: inline-block;
}
.st-scrolling .st-section {
padding: 0 5px;
}
/* // 向左匀速滚动动画 */
.st-scrolling {
animation: scroll 10s linear infinite;
}
@keyframes scroll {
/* 0% {
transform: translate3d(0%, 0, 0);
}
100% {
transform: translate3d(-50%, 0, 0);
} */
0% {
transform: translateX(300px);
-webkit-transform: translateX(300px);
}
100% {
transform: translateX(-100%);
-webkit-transform: translateX(-100%);
}
}