当前位置:网站首页>JS to achieve the effect of text marquee
JS to achieve the effect of text marquee
2022-06-26 03:42:00 【Mr. Gao's cat】

<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
<title> Text scrolling </title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
body {
font: 12px/1 ' Microsoft YaHei ';
}
.wrap {
border: 1px solid #000;
font-size: 14px;
color: #333;
padding: 5px;
white-space: nowrap;
overflow: hidden;
width: 300px;
}
.box {
width: 1000px;
overflow: hidden;
}
.box p {
display: inline-block;
}
</style>
</head>
<body>
<!-- Rolling containers -->
<div id="wrap" class="wrap">
<div class="box">
<p class="txt"> Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat , Mr. Gao's cat ,</p>
</div>
</div>
<script>
let wrap = document.getElementById('wrap');
let box = wrap.getElementsByTagName('div')[0];
let p = document.getElementsByTagName('p')[0];
let p_w = p.offsetWidth;
let wrap_w = wrap.offsetWidth;
window.onload = function fun() {
if (wrap_w > p_w) { return false; }
box.innerHTML += box.innerHTML;
setTimeout("fun1()", 50);
}
function fun1() {
if (p_w > wrap.scrollLeft) {
wrap.scrollLeft++;
setTimeout("fun1()", 15); // The smaller, the faster
}
else {
setTimeout("fun2()", 50);
}
}
function fun2() {
wrap.scrollLeft = 0;
fun1();
}
</script>
</body>
</html>
边栏推荐
- Do you want to add a key to the applet or for sequence?
- Multimedia elements, audio, video
- 路由跳轉之點擊列錶的操作按鈕,跳轉至另一個菜單頁面並激活相應的菜單
- General operations of asynctask
- Binary search
- Group counting notes - instruction pipeline of CPU
- HL7Exception: Can‘t XML-encode a GenericMessage. Message must have a recognized struct
- Class diagram
- Communication mode between processes
- Where is it safe to open a fund account?
猜你喜欢

Run multiple main functions in the clion project

After Ali failed to start his job in the interview, he was roast by the interviewer in the circle of friends (plug)

Uni app custom navigation bar component

Digital twin intelligent water service, breaking through the development dilemma of sponge City

Redux thunk simple case, advantages, disadvantages and thinking

给网站添加“开放搜索描述“以适配浏览器的“站点搜索“

todolist未完成,已完成

Todolist incomplete, completed

请求对象,发送请求

The role of children's programming in promoting traditional disciplines in China
随机推荐
Using meta analysis to drive the development of educational robot
Insect structure and Deconstruction
After Ali failed to start his job in the interview, he was roast by the interviewer in the circle of friends (plug)
Todolist incomplete, completed
Procédures stockées MySQL
请求对象,发送请求
progress bar
String到底能不能改变?
Inkscape如何将png图片转换为svg图片并且不失真
Request object, send request
Digital twin intelligent water service, breaking through the development dilemma of sponge City
多媒体元素,音频、视频
js实现文字跑马灯效果
数字孪生智慧水务,突破海绵城市发展困境
The kotlin project is running normally and the R file cannot be found
USB driver -debug
Communication mode between processes
Drag and drop
mysql存储过程
MySQL高级部分( 四: 锁机制、SQL优化 )