当前位置:网站首页>[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>
边栏推荐
- Redis的4种缓存模式分享
- Understand Alibaba cloud's secret weapon "dragon architecture" in the article "science popularization talent"
- 怎么判断外盘期货平台正规,资金安全?
- 【大连理工大学】考研初试复试资料分享
- Width accuracy
- Guitar Pro 8win10 latest guitar learning / score / creation
- 宽度与对齐
- 从0到1建设智能灰度数据体系:以vivo游戏中心为例
- LNX efficient search engine, fastdeploy reasoning deployment toolbox, AI frontier paper | showmeai information daily # 07.04
- 音视频技术开发周刊 | 252
猜你喜欢
MySQL学习笔记——数据类型(2)
干货 | fMRI标准报告指南新鲜出炉啦,快来涨知识吧
Book of night sky 53 "stone soup" of Apache open source community
Case sharing | integrated construction of data operation and maintenance in the financial industry
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
Redis publish and subscribe
直播预告 | PostgreSQL 内核解读系列第二讲:PostgreSQL 体系结构
Weekly recruitment | senior DBA annual salary 49+, the more opportunities, the closer success!
I plan to teach myself some programming and want to work as a part-time programmer. I want to ask which programmer has a simple part-time platform list and doesn't investigate the degree of the receiv
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
随机推荐
【读书会第十三期】 音频文件的封装格式和编码格式
What is the future of the booming intelligent Internet of things (aiot) in recent years?
Usage of database functions "recommended collection"
CentOS 6.3 下 PHP编译安装JSON模块报错解决
Unity animation day05
Unity script API - GameObject game object, object object
Scientific research cartoon | what else to do after connecting with the subjects?
Logstash ~ detailed explanation of logstash configuration (logstash.yml)
Unity脚本常用API Day03
进制乱炖
数据库函数的用法「建议收藏」
unity update 协程_Unity 协程的原理
Who the final say whether the product is good or not? Sonar puts forward performance indicators for analysis to help you easily judge product performance and performance
Intelligent customer service track: Netease Qiyu and Weier technology play different ways
Live broadcast preview | PostgreSQL kernel Interpretation Series II: PostgreSQL architecture
LeetCode 58. Length of the last word
Weibo and Huya advance into interest communities: different paths for peers
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
web聊天室实现
Building intelligent gray-scale data system from 0 to 1: Taking vivo game center as an example