当前位置:网站首页>Running lantern effect JS text rotation effect realization
Running lantern effect JS text rotation effect realization
2022-06-30 06:58:00 【Zmmm Jun】
The author introduces :13 Class a graduate , At present, I graduated for one year , Former place of employment: Beijing , One year in office . Little rookie at the front , The former company was a small start-up company , When I graduated, I did python The backend development , Because front-end personnel are nervous , Later, I mainly participated in front-end page development . I have done data analysis and data cleaning in agriculture before , Agricultural page data visualization ,CMS System development . Now Changsha , Mainly responsible for Web Development ,H5 page , Small programs and other front-end work
Current technical capabilities : I have been studying hard JS Object oriented development ,Vue.js Related technology stack ,Webpack Packaging tools , Applet development ,H5 Mobile page development
Be neither arrogant nor rash , One step at a time , Take advantage of this time to sum up , Good precipitation
good , I don't say much nonsense , Let's get to the point
# Running lamp effect JS The text rotation effect is realized
Realize the idea :
css scrollTop Attributes can control the pixels of the element that are hidden above the content area .
- ###### This attribute can be used when the parent element is smaller than the child element
- ###### Copy an element to realize the effect of running lantern cycle ( Cycle from bottom to top )
- ###### utilize js Timer to achieve animation , When scrollTop Equal to the height of the child element ,scrollTop Set to 0
- Code implementation :
html:
<div class = 'testScroll' id="scrollBlock">
<ul class="scrollItem" id="contentBlock">
<li> Running lights </li>
</ul>
</div>
css:
Set the child element slightly higher than the parent element , Parent element overflow:hidden Can achieve hidden effect
ul li{
list-style: none;
}
body{
background-color: #f3f3f3
}
.testScroll{
overflow: hidden;
height: 4rem;
background-color: #fff;
}
#contentBlock{
margin-top: 0;
margin-bottom: 0;
height: 101%;
}
JS:
function zMarquee(parentDom,childDom,speedParam,stayTime){
if(parentDom && childDom){
var parent = document.getElementById(parentDom);
var child = document.getElementById(childDom);
var childHeight = child.offsetHeight; // Content height of running lamp
var speed = speedParam?speedParam:40; // Running light speed
var timer = null;
var delay = stayTime?stayTime:1000; // The default hold time is
parent.scrollTop = 1;
parent.innerHTML += parent.innerHTML;
var start_scroll = function(){
timer = setInterval(scrollUp,speed);
parent.scrollTop++;
}
var scrollUp = function(){
if(Math.round(parent.scrollTop)%(childHeight*2)==0){
clearInterval(timer);
setTimeout(start_scroll,10);
parent.scrollTop = parent.scrollTop + 1;
}else{
if(parent.scrollTop >= childHeight){
parent.scrollTop = 0;
}
parent.scrollTop++;
}
}
if(parent.offsetHeight < childHeight){
start_scroll()
}else{
console.error("zMarquee throw a error ,parentDom's height is more than childDom's ")
}
}else{
console.error('zMarquee Param illegal !')
}
}
zMarquee('scrollBlock','contentBlock',20)
Simple code , Simply encapsulates a method , Parameters are parent and child elements ID, The optional parameter is speed, It's not bad , Other methods can continue to enrich
边栏推荐
- 编写并运行第一个Go语言程序
- 史上最全一句话木马
- Pay attention to this live broadcast and learn about the path to achieve the dual carbon goal of the energy industry
- [mask RCNN] target detection and recognition based on mask RCNN
- Keil - the "trace HW not present" appears during download debugging
- 汇编语言学习一(有栈协程铺垫,32位寄存器和相关指令学习,未完待续06/29)
- RT thread Kernel Implementation (III): implementation of idle threads and blocking delay
- 第一行代码(第三版)学习笔记
- ROS program compilation, like no compilation, refers to the execution of the old compiled executable program
- Huawei full-scale Daniel shared the 598 page full-color Manual of network protocols for the first time
猜你喜欢

Jingwei Hengrun won the 10ppm quality award of paccar group again

Bat 使用细节2

1.5 - logical operation

Unity中实现溶解(Dissolve)特效及其原理解析

Xshell传输文件

Go常用命令

RT thread migration to s5p4418 (IV): thread synchronization

【模糊神经网络】基于模糊神经网络的移动机器人路径规划
![[daily question] 535 Encryption and decryption of tinyurl](/img/73/35674cd5df3d937af0762645041421.png)
[daily question] 535 Encryption and decryption of tinyurl
![[Hot100]回文子串 与 最长回文子串](/img/a5/10dec640f02023c4d55cb42e6309fb.png)
[Hot100]回文子串 与 最长回文子串
随机推荐
[Hot100]回文子串 与 最长回文子串
First line of code (Third Edition) learning notes
原理:WebMvcConfigurer 与 WebMvcConfigurationSupport避坑指南
freemarker
Google Earth engine (GEE) - Murray global tidal wetland change V1 (1999-2019) data set
SOC_ SD_ CLK
Idea shortcut key
Principle: webmvcconfigurer and webmvcconfigurationsupport pit avoidance Guide
MySQL Optimization: from more than ten seconds to 300 milliseconds
1.8 - multi level storage
Porting RT thread to s5p4418 (II): dynamic memory management
File transfer protocol, FTP file sharing server
Problems and solutions of creating topic messages in ROS
第一行代码(第三版)学习笔记
Four tips in numpy
Graphic octet, really top
1.4 - fixed and floating point numbers
ETL为什么经常变成ELT甚至LET?
Steps for formulating class or file templates in idea
Goland常用快捷键设置