当前位置:网站首页>JS实现文字滚动 跑马灯效果
JS实现文字滚动 跑马灯效果
2022-07-04 03:47:00 【Undefind_object】
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
#scroll_div {
height: 30px;
line-height: 30px;
overflow:hidden;
white-space: nowrap;
width: 800px;
background-color: #23527c;
color: #d8d8d8;
margin: 1rem 0;
text-align: center;
}
#scroll_begin,#scroll_end {
display: inline;
}
</style>
</head>
<body>
<div id="scroll_div">
<div id="scroll_begin">
<span class="pad_right">这是第一条啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊</span>
</div>
<div id="scroll_end"></div>
</div>
<script>
function ScrollImgLeft() {
var speed = 20;//初始化速度 也就是字体的整体滚动速度
var MyMar = null;//初始化一个变量为空 用来存放获取到的文本内容
var scroll_begin = document.getElementById("scroll_begin");//获取滚动的开头id
var scroll_end = document.getElementById("scroll_end");//获取滚动的结束id
var scroll_div = document.getElementById("scroll_div");//获取整体的开头id
scroll_end.innerHTML = scroll_begin.innerHTML;//滚动的是html内部的内容,原生知识!
//定义一个方法
function Marquee() {
if (scroll_end.offsetWidth - scroll_div.scrollLeft <= 0){
scroll_div.scrollLeft -= scroll_begin.offsetWidth;
} else{
scroll_div.scrollLeft++;
}
}
MyMar = setInterval(Marquee, speed);
//滑入暂停
scroll_div.onmouseover = function () {
clearInterval(MyMar);
}
//滑出继续
scroll_div.onmouseout = function () {
MyMar = setInterval(Marquee, speed);
}
}
ScrollImgLeft();
</script>
</body>
</html>
边栏推荐
- Redis cluster uses Lua script. Lua script can also be used for different slots
- Balance between picture performance of unity mobile game performance optimization spectrum and GPU pressure
- 深度优先搜索简要讲解(附带基础题)
- Pandora IOT development board learning (HAL Library) - Experiment 6 independent watchdog experiment (learning notes)
- Infiltration practice guest account mimikatz sunflower SQL rights lifting offline decryption
- Cesiumjs 2022^ source code interpretation [0] - article directory and source code engineering structure
- idea修改主体颜色
- Getting started with the go language is simple: go implements the Caesar password
- The maximum expiration time of client secret in azure ad application registration is modified to 2 years
- Tcpclientdemo for TCP protocol interaction
猜你喜欢

Go 语言入门很简单:Go 实现凯撒密码

National standard gb28181 protocol platform easygbs fails to start after replacing MySQL database. How to deal with it?

Sales management system of lightweight enterprises based on PHP

pytest多进程/多线程执行测试用例

拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。

Nbear introduction and use diagram

How about the ratings of 2022 Spring Festival Gala in all provinces? Map analysis helps you show clearly!

Pytest multi process / multi thread execution test case

Perf simple process for multithreaded profile

SQL语句加强练习(MySQL8.0为例)
随机推荐
10 reasons for not choosing to use free virtual hosts
Object oriented -- encapsulation, inheritance, polymorphism
postgresql 用户不能自己创建表格配置
【华为云IoT】读书笔记之《万物互联:物联网核心技术与安全》第3章(上)
system information
[book club issue 13] multimedia processing tool ffmpeg tool set
拼夕夕二面:说说布隆过滤器与布谷鸟过滤器?应用场景?我懵了。。
Go 语言入门很简单:Go 实现凯撒密码
[paddleseg source code reading] paddleseg custom data class
Redis cluster uses Lua script. Lua script can also be used for different slots
图解网络:什么是热备份路由器协议HSRP?
投资深度思考
[Huawei cloud IOT] reading notes, "Internet of things: core technology and security of the Internet of things", Chapter 3 (I)
[source code analysis] model parallel distributed training Megatron (5) -- pipestream flush
数据库SQL语句汇总,持续更新......
【读书会第十三期】多媒体处理工具 FFmpeg 工具集
Is it really so difficult to learn redis? Today, a fan will share his personal learning materials!
Value transfer communication between components (parent to child, child to parent, brother component to value)
[PaddleSeg 源码阅读] PaddleSeg计算Dice
JVM family -- monitoring tools