JavaScript实现竖直文本滚动

JavaScript实现竖直文本滚动

一、HTML代码

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="content-type" content="text/html;charset=utf-8">
	<title>Scroll Text</title>
	<link rel="stylesheet" type="text/css" href="scrollText.css">

</head>
<body>
	<div class="news_root">
		<div class="news_header">HeaderLine</div>
		<div id="scrollContainer">
			<div id="scrollContent">
				<a href="#">w3c has released html5</a>
				<a href="#">w3c has released css3</a>
				<a href="#">w3c has released ecmasript5</a>
				<a href="#">w3c has released ria</a>
				<a href="#">w3c has released html5 bom</a>
				<a href="#">w3c has released ria</a>
				<a href="#">w3c has released html5 bom</a>
			</div>
		</div>
	</div>
	<script type="text/javascript" src="scrollText.js"></script>
</body>
</html>

二、CSS代码

body
{
	font-size:15px;
	font-family: 'Microsoft YaHei','微软雅黑','SimSun','宋体';
	margin: 0px;
	padding: 0px;
	text-align: center;
}
a
{
	color:#666666;
	text-decoration: none;
	display: block;
	line-height: 1.5em;
}
a:hover
{
	color: #CC0000;
	text-decoration: none;
}
.news_root
{
	width: 255px;
	height: 134px;
	text-align: left;
	margin: 0 auto;
	border: 1px solid #ccc;
}
.news_header
{
	width: 243px;
	height: 16px;
	vertical-align: top;
	text-align: left;
	font-size: 14px;
	padding: 6px;
	background-color: #ccc;
}
#scrollContainer
{
	width: 245px;
	margin: 2px 5px;
	overflow: hidden;
	text-align: left;
}

三、Javascript代码

var stopscroll = false;
var scrollContHeight = 95;   //滚动区域的高度
var scrollContWidth = 230;   //滚动区域的宽度
var scrollSpeed = 25;        //滚动的速度,越小滚动越快

var scrollContainer = document.getElementById("scrollContainer");
var scrollContent = document.getElementById("scrollContent");
do
{
	scrollContainer.appendChild(scrollContent.cloneNode(true));
}while(scrollContainer.offsetHeight < scrollContHeight);

scrollContainer.style.width = scrollContWidth+"px";
scrollContainer.style.height = scrollContHeight+"px";
scrollContainer.noWrap = true;

//加入�事件:鼠标经过,停止滚动;鼠标离开,继续滚动
scrollContainer.onmouseover = new Function("stopscroll = true");
scrollContainer.onmouseout = new Function("stopscroll = false");

function init()
{
	scrollContainer.scrollTop = 0;
	setInterval(scrollUp,scrollSpeed);
}
init();

var currTop = 0;
function scrollUp()
{
	if(stopscroll == true)
		return;
	currTop = scrollContainer.scrollTop;
	scrollContainer.scrollTop += 1;
	if(currTop == scrollContainer.scrollTop)
	{
		scrollContainer.scrollTop = 0;
		scrollContainer.scrollTop += 1;
	}
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/119017.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 视觉slam与激光slam_适马fpl 视频

    视觉slam与激光slam_适马fpl 视频SLAM(同步定位与地图构建),是指运动物体根据传感器的信息,一边计算自身位置,一边构建环境地图的过程,解决机器人等在未知环境下运动时的定位与地图构建问题。目前,SLAM的主要应用于机器人、无人机、无人驾驶、AR、VR等领域。其用途包括传感器自身的定位,以及后续的路径规划、运动性能、场景理解。SLAM按照传感器来分,分为视觉SLAM(VSLAM)和激光SLAM,视觉SLAM基于摄像

    2022年8月23日
    6
  • table如何设置边框4*16_html设置表格边框

    table如何设置边框4*16_html设置表格边框1.通过table标签的属性来设置,border=”1″边框设置为1,cellspacing=”0″单元格间距设置为0.2.通过css样式设置,而且用css可以自动设置边框的粗细、颜色等。

    2026年1月28日
    3
  • 搞定Prometheus普罗米修斯监控系统

    搞定Prometheus普罗米修斯监控系统学习目录能够安装prometheus服务器 能够通过安装node_exporter监控远程linux 能够通过安装mysqld_exporter监控远程mysql数据库 能够安装grafana 能够在grafana添加prometheus数据源 能够在grafana添加监控cpu负载的图形 能够在grafana图形显示mysql监控数据 能够通过grafana+onealert实现报警任务背景AAA公司是一家电商网站,由于公司的业务快速发展,公司要求对现有机器进行为业务监控,责成运维

    2022年7月19日
    63
  • 单片机入门级视频教程「建议收藏」

    单片机入门级视频教程「建议收藏」对于入门级网友,向大家推荐郭天祥的《十天学会单片机c语言》,简单明了。想亲自做试验,不妨花点钱买他的实验板教程从电驴资源网就能下载

    2022年5月22日
    46
  • 十进制,BCD数怎样转8421BCD码

    十进制,BCD数怎样转8421BCD码BCD 数是一种采用 4 位二进制数表示 1 位十进制数 0 9 而得到的数 nbsp nbsp nbsp nbsp 例如 89 的 BCD 码为 相当于将 89 中的 8 和 9 分别转为二进制 而可以得出 BCD 码 nbsp nbsp nbsp nbsp 则可以得出 89 的 BCD 数为 0 nbsp nbsp nbsp nbsp 接下来就是将此 BCD 码转为 8421BCD 码了 其实很简单 将每个分别转

    2025年6月21日
    5
  • ES6—new Promise()讲解,Promise对象是用来干嘛的?应该怎么用?使用场景有哪些?

    ES6—new Promise()讲解,Promise对象是用来干嘛的?应该怎么用?使用场景有哪些?ES6Promise先拉出来遛遛复杂的概念先不讲,我们先简单粗暴地把Promise用一下,有个直观感受。那么第一个问题来了,Promise是什么玩意呢?是一个类?对象?数组?函数?别猜了,直接打印出来看看吧,console.dir(Promise),就这么简单粗暴。这么一看就明白了,Promise是…

    2022年4月30日
    88

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号