简体   繁体   English

纯CSS新闻/资讯提供

[英]pure css news/info feed

I have some code that works fine, it simply adds a horizontal news feed (or any information I list) It works good with no flicker but when I add more data to it, it seems to take a while to load and the speed changes? 我有一些运行良好的代码,它只是添加了一个水平新闻提要(或我列出的任何信息),并且没有闪烁,但运行良好,但是当我向其中添加更多数据时,加载似乎需要一段时间并且速度会发生变化? I have quite a lot more information to add to it but I dont want to keep changing the speed everytime the data is changed. 我有很多要添加的信息,但我不想每次更改数据时都保持更改速度。

Any help would be great, thanks 任何帮助都很好,谢谢

 @keyframes customticker { 0% { -webkit-transform: translate3d(100%, 0, 0); transform: translate3d(100%, 0, 0); visibility: visible; } 100% { -webkit-transform: translate3d(-100%, 0, 0); transform: translate3d(-100%, 0, 0); } } /* Formatting the full-width ticker wrapper background and font color */ #tickerwrap { width: 100%; overflow: hidden; background-color: rgba(0, 0, 0, 0.5); color: #fff; } /* Formatting the ticker content background, font color, padding and exit state */ #ticker { display: inline-block; white-space: nowrap; -webkit-animation-iteration-count: infinite; animation-iteration-count: infinite; -webkit-animation-timing-function: linear; animation-timing-function: linear; -webkit-animation-name: customticker; animation-name: customticker; -webkit-animation-duration: 70s; animation-duration: 70s; } 
 <div id="tickerwrap"> <div id="ticker"> Avon <span style="color: #333638"> | </span> Bedfordshire <span style="color: #333638"> | </span> Buckinghamshire <span style="color: #333638"> | </span> Cambridgeshire <span style="color: #333638"> | </span> Cheshire <span style="color: #333638"> | </span> Cleveland <span style="color: #333638"> | </span> Clwyd <span style="color: #333638"> | </span> Cornwall <span style="color: #333638"> | </span> County Antrim <span style="color: #333638"> | </span> County Armagh<span style="color: #333638"> | </span> County Down<span style="color: #333638"> | </span> County Fermanagh<span style="color: #333638"> | </span> C ounty Londonderry<span style="color: #333638"> | </span> County Tyrone <span style="color: #333638"> | </span> Cumbria <span style="color: #333638"> | </span> Derbyshire <span style="color: #333638"> | </span> Devon <span style="color: #333638"> | </span> Dorset <span style="color: #333638"> | </span> Dumfries <span style="color: #333638"> | </span> Galloway <span style="color: #333638"> | </span> Durham <span style="color: #333638"> | </span> Dyfed <span style="color: #333638"> | </span> East Sussex <span style="color: #333638"> | </span> Essex <span style="color: #333638"> | </span> Fife <span style="color: #333638"> | </span> Gloucestershire <span style="color: #333638"> | </span> Grampian <span style="color: #333638"> | </span> Greater Manchester <span style="color: #333638"> | </span> Gwent <span style="color: #333638"> | </span> Gwynedd County <span style="color: #333638"> | </span> Hampshire <span style="color: #333638"> | </span> Herefordshire </div> </div> 

But I want to add more data to it without it taking ages to load. 但是我想为其添加更多数据,而不会花费很多时间。

Thanks 谢谢

Solution with margin-left & transform-origin margin-lefttransform-origin解决方案

I've got a tricky solution with margin-left & transform-origin . 我有margin-lefttransform-origin一个棘手的解决方案。

 @keyframes customticker { 0% { margin-left: 100%; transform: translateX(0); } 100% { margin-left: 0%; transform: translateX(-100%); } } #tickerwrap { width: 100%; overflow: hidden; background-color: black; } #ticker { display: inline-block; color: white; white-space: nowrap; transform-origin: 100% 0; animation-iteration-count: infinite; animation-timing-function: linear; animation-name: customticker; animation-duration: 60s; } #ticker span { color: grey; } 
 <div id="tickerwrap"> <div id="ticker"> Avon <span>|</span> Bedfordshire <span>|</span> Buckinghamshire <span>|</span> Cambridgeshire <span>|</span> Cheshire <span>|</span> Cleveland <span>|</span> Clwyd <span>|</span> Cornwall <span>|</span> County Antrim <span>|</span> County Armagh <span>|</span> County Down <span>|</span> County Fermanagh <span>|</span> County Londonderry <span>|</span> County Tyrone <span>|</span> Cumbria <span>|</span> Derbyshire <span>|</span> Devon <span>|</span> Dorset <span>|</span> Dumfries <span>|</span> Galloway <span>|</span> Durham <span>|</span> Dyfed <span>|</span> East Sussex <span>|</span> Essex <span>|</span> Fife <span>|</span> Gloucestershire <span>|</span> Grampian <span>|</span> Greater Manchester <span>|</span> Gwent <span>|</span> Gwynedd County <span>|</span> Hampshire <span>|</span> Herefordshire </div> </div> 

Solution with padding-left & padding-right padding-left padding-right padding-left解决方案

Or the solution proposed by @Jules with padding-left & padding-right . 或者@Jules提出的padding-leftpadding-right解决方案。

 @keyframes ticker { 0% { transform: translateX(0); } 100% { transform: translateX(-100%); } } #tickerwrap { width: 100%; overflow: hidden; background-color: black; padding-left: 100%; } #ticker { display: inline-block; color: white; white-space: nowrap; padding-right: 100%; animation-iteration-count: infinite; animation-timing-function: linear; animation-name: ticker; animation-duration: 60s; } #ticker span { color: grey; } 
 <div id="tickerwrap"> <div id="ticker"> Avon <span>|</span> Bedfordshire <span>|</span> Buckinghamshire <span>|</span> Cambridgeshire <span>|</span> Cheshire <span>|</span> Cleveland <span>|</span> Clwyd <span>|</span> Cornwall <span>|</span> County Antrim <span>|</span> County Armagh <span>|</span> County Down <span>|</span> County Fermanagh <span>|</span> County Londonderry <span>|</span> County Tyrone <span>|</span> Cumbria <span>|</span> Derbyshire <span>|</span> Devon <span>|</span> Dorset <span>|</span> Dumfries <span>|</span> Galloway <span>|</span> Durham <span>|</span> Dyfed <span>|</span> East Sussex <span>|</span> Essex <span>|</span> Fife <span>|</span> Gloucestershire <span>|</span> Grampian <span>|</span> Greater Manchester <span>|</span> Gwent <span>|</span> Gwynedd County <span>|</span> Hampshire <span>|</span> Herefordshire </div> </div> 

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

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