当前位置:网站首页>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>
边栏推荐
- Communication mode between processes
- redux-thunk 简单案例,优缺点和思考
- Is it safe for individuals to buy stocks with flush software? How to buy stocks
- String到底能不能改变?
- Butterknife unbinder uses flashback in fragment and viewpager
- mysql存储过程
- Nebula Graph学习篇3_多线程完成6000w+关系数据迁移
- 图扑软件数字孪生海上风电 | 向海图强,奋楫争先
- 用元分析法驱动教育机器人的发展
- 给网站添加“开放搜索描述“以适配浏览器的“站点搜索“
猜你喜欢

多媒体元素,音频、视频

MySQL development environment

上传文件/文本/图片,盒子阴影

Nebula Graph学习篇3_多线程完成6000w+关系数据迁移

云计算基础-0

QT compilation error: unknown module (s) in qt: script
![[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long](/img/82/6a81e5b0d5117d780ce5910698585a.jpg)
[hash table] a very simple zipper hash structure, so that the effect is too poor, there are too many conflicts, and the linked list is too long

项目部署遇到的问题-生产环境

The role of children's programming in promoting traditional disciplines in China

计组笔记——CPU的指令流水
随机推荐
Cloud Computing Foundation -0
指南针app是正规的吗?到底安不安全
经典模型——ResNet
MySQL addition, deletion, query and modification (Advanced)
图扑软件数字孪生海上风电 | 向海图强,奋楫争先
navicat16无线试用
栖霞消防开展在建工地消防安全培训
JS array array JSON de duplication
Is it safe to open a fund account? How to apply
Various errors in kitti2bag installation
Insect structure and Deconstruction
progress bar
USB driver -debug
QT compilation error: unknown module (s) in qt: script
Todolist incomplete, completed
USB peripheral driver - Enumeration
Drag and drop
虫子 构造与析构
Cliquez sur le bouton action de la liste pour passer à une autre page de menu et activer le menu correspondant
Qixia fire department carries out fire safety training on construction site