当前位置:网站首页>[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>
边栏推荐
- 数据湖治理:优势、挑战和入门
- Data Lake Governance: advantages, challenges and entry
- Redis的4种缓存模式分享
- 找数字
- Unity脚本介绍 Day01
- 科研漫画 | 联系到被试后还需要做什么?
- Deep learning neural network case (handwritten digit recognition)
- Intelligent customer service track: Netease Qiyu and Weier technology play different ways
- Unity script API - component component
- Helix swarm Chinese package is released, and perforce further improves the user experience in China
猜你喜欢
压力、焦虑还是抑郁? 正确诊断再治疗
Lombok使用引发的血案
Quelles sont les perspectives de l'Internet intelligent des objets (aiot) qui a explosé ces dernières années?
Understand the context in go language in an article
Deep learning neural network case (handwritten digit recognition)
Redis publier et s'abonner
Force button brush question 01 (reverse linked list + sliding window +lru cache mechanism)
The per capita savings of major cities in China have been released. Have you reached the standard?
Unity动画Animation Day05
开源人张亮的 17 年成长路线,热爱才能坚持
随机推荐
Flutter reports an error no mediaquery widget ancestor found
MySQL index optimization
Analysis of nearly 100 million dollars stolen and horizon cross chain bridge attacked
深入JS中几种数据类型的解构赋值细节
C implementation defines a set of intermediate SQL statements that can be executed across libraries
Width and alignment
一篇文章学会GO语言中的变量
The 17 year growth route of Zhang Liang, an open source person, can only be adhered to if he loves it
Big God explains open source buff gain strategy live broadcast
MySQL~MySQL给已有的数据表添加自增ID
【读书会第十三期】FFmpeg 查看媒体信息和处理音视频文件的常用方法
Unity预制件Prefab Day04
Dry goods | fMRI standard reporting guidelines are fresh, come and increase your knowledge
Data Lake Governance: advantages, challenges and entry
go-zero微服务实战系列(九、极致优化秒杀性能)
Numpy notes
Unity脚本API—GameObject游戏对象、Object 对象
华为云数据库DDS产品深度赋能
[learning notes] matroid
每周招聘|高级DBA年薪49+,机会越多,成功越近!