当前位置:网站首页>[native JS] optimized text rotation effect
[native JS] optimized text rotation effect
2022-07-04 15:41:00 【dongZhenSong】
2020 The old project in the new company (JS) There is a need to develop text rotation , I found many schemes on the Internet , There are always some details that are flawed . Studied for half a day , Finally, a set of personal satisfaction native JS Text rotation effect .
The effect is as follows ( Briefly : Infinite rotation , Silky switch ):

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<title> Optimized text rotation </title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"> </script>
<style type="text/css"> #rolling_noti{
width: 100%; height: 45px; background: #FCFE7B; display: flex; } .box{
-webkit-flex: 1; flex: 1; } #right_div{
display: inline-block; background: url("source/close.jpeg") no-repeat right; padding-right: 36px; line-height: 36px; } .winBox{
font-family: PingFangSC-Regular; font-size: 14px; color: #FF721F; letter-spacing: 0; text-align: left; height: 40px; overflow: hidden; position: relative; } /* Solve the last problem under Android models li Line breaking questions ,ul Set not to wrap ,li Set up display:inline-block*/ #scroll_loudspeaker{
/* Be careful :width The true value of is determined by the internal li The length and quantity of .*/ width: 900px; position: absolute; left: 0; top: 0; white-space: nowrap; margin: 0; } #scroll_loudspeaker li{
list-style: none; display: inline-block; line-height: 40px; text-align: left; overflow: hidden; text-decoration: none; } #rolling_noti span{
display: inline-block; width: 25px; height: 25px; } .content_li{
background-color: blue; } .li_div{
background: url("source/loudspeaker.jpeg") no-repeat left; padding-left: 36px; line-height: 36px; } </style>
</head>
<body>
<div id="rolling_noti">
<div id="rolling_div" style="-webkit-flex: 1;flex: 1;height: 100%;overflow: hidden;text-overflow: ellipsis; -webkit-align-items: center;align-items: center;display: flex;white-space: nowrap">
<div class="box">
<div class="winBox">
<ul id="scroll_loudspeaker">
fklsjfald
</ul>
</div>
</div>
</div>
<div id="right_div" style=""></div>
</div>
<script type="text/javascript"> var ulAnimateLeft = 0; function clearRollingNotiTimer(){
} $("#scroll_loudspeaker").html(" In the initialization ..."); var _this = this; let noticeTips = [' Zhang San Win. 1000 element '," Li Si Win. 300 element "," Wang Wu Win. 870 element "]; let noticeLength = noticeTips.length; var lis = ""; for (var i = 0; i < noticeLength; i++) {
lis+= ( "<li class='content_li'>" +'<div class="li_div"><strong>'+noticeTips[i]+'</strong></div>' ) ; } // Infinite round robin optimization : Add a... To the last face li, present A-B-C-D-A In the form of ,D After playing, go to A if (noticeLength > 0) {
lis+= ( "<li class='content_li'>" +'<div class="li_div"><strong>'+noticeTips[0]+'</strong></div>' ) ; } $('#scroll_loudspeaker').html(lis); clearRollingNotiTimer(); let singleWidth = screen.width-50; // ABCD The length of the content let infoUlLength = singleWidth * noticeLength; // ABCDA The length of the content let ulLength = infoUlLength + singleWidth; // Set dynamic ul length $('#scroll_loudspeaker').css('width',ulLength+'px'); $('.content_li').css('width',singleWidth+'px'); console.warn("a,b",singleWidth,infoUlLength); // Note that pages should be destroyed when they die timer, Reinitialize when entering the page var timer = setInterval(function () {
// Play to the last time , Turn to the first if(ulAnimateLeft== -infoUlLength){
ulAnimateLeft = 0; } ulAnimateLeft-=1; console.info("ulAnimateLeft:",ulAnimateLeft); $('#scroll_loudspeaker').css({
left:ulAnimateLeft }) }); </script>
</body>
</html>
边栏推荐
- How did the beyond concert 31 years ago get super clean and repaired?
- 十六进制
- Solve the error of JSON module in PHP compilation and installation under CentOS 6.3
- Shell programming basics
- Flutter reports an error no mediaquery widget ancestor found
- [Dalian University of technology] information sharing of postgraduate entrance examination and re examination
- Functional interface, method reference, list collection sorting gadget implemented by lambda
- Shell 编程基础
- Book of night sky 53 "stone soup" of Apache open source community
- Helix swarm Chinese package is released, and perforce further improves the user experience in China
猜你喜欢

MySQL index optimization

Weibo and Huya advance into interest communities: different paths for peers

. Net applications consider x64 generation

Unity animation day05

Big God explains open source buff gain strategy live broadcast

MYSQL索引优化

Functional interface, method reference, list collection sorting gadget implemented by lambda

Redis publish and subscribe

.Net 应用考虑x64生成

They are all talking about Devops. Do you really understand it?
随机推荐
Redis哨兵模式实现一主二从三哨兵
MySQL federated primary key_ MySQL creates a federated primary key [easy to understand]
selenium 浏览器(2)
进制形式
Decimal, exponential
宽度精度
CentOS 6.3 下 PHP编译安装JSON模块报错解决
Unity script API - time class
Logstash~Logstash配置(logstash.yml)详解
2022年九大CIO趨勢和優先事項
C implementation defines a set of intermediate SQL statements that can be executed across libraries
[book club issue 13] packaging format and coding format of audio files
音视频技术开发周刊 | 252
MySQL learning notes - data type (numeric type)
Unity脚本生命周期 Day02
Unity脚本常用API Day03
MySQL组合索引(多列索引)使用与优化案例详解
LeetCode 1184. 公交站间的距离 ---vector顺逆时针
案例分享|金融业数据运营运维一体化建设
LeetCode 35. 搜索插入位置 —vector遍历(O(logn)和O(n)的写法---二分查找法)