Javascript 如何以有限的高度滚动div上的文本?

Javascript 如何以有限的高度滚动div上的文本?,javascript,Javascript,因此,我的页面上有不适合的段落块,我的解决方案是使用滚动方法,这样当用户悬停在向下箭头上时,它将向下滚动段落并显示更多文本 所以我附上了我的项目的图像,正如你所看到的,我有向下滚动和向上滚动按钮 以下是我的项目的HTML文件: <div id="content1" class="scrolling-content"> <div> <div id="story" style="overflow:

因此,我的页面上有不适合的段落块,我的解决方案是使用滚动方法,这样当用户悬停在向下箭头上时,它将向下滚动段落并显示更多文本

所以我附上了我的项目的图像,正如你所看到的,我有向下滚动和向上滚动按钮

以下是我的项目的HTML文件:

<div id="content1" class="scrolling-content">
                <div>
                    <div id="story" style="overflow:hidden; width:40%;">
                        <h2 style="font-size:30px;">Quirino's Story</h2>
                            <p>Elpidio Quirino was a Filipino politician, and the sixth President           of the Philippines.</p>
                            <p>He was born in Vigan, Ilocos Sur to Mariano Quirino and Gregoria Rivera, Quirino spent his early years in Aringay, La Union. He received secondary education at Vigan High School, then went to Manila where he worked as junior computer in the Bureau of Lands and as property clerk in the Manila police department. He graduated from Manila High School in 1911 and also passed the civil service examination, first-grade.</p>

                            <p>Quirino attended the University of the Philippines. In 1915, he earned his law degree from the university's College of Law, and was admitted to the bar later that year. He was engaged in the private practice of law until he was elected as member of the Philippine House of Representatives from 1919 to 1925, then as Senator from 1925 to 1931. He then served as Secretary of Finance and Secretary of the Interior in the Commonwealth government.</p>

                            <p>In 1934, Quirino was a member of the Philippine Independence mission to Washington D.C., headed by Manuel L. Quezon that secured the passage in the United States Congress of the Tydings-McDuffie Act. This legislation set the date for Philippine independence by 1945. Official declaration came on July 4, 1946.</p>

                            <p>During the Battle of Manila in World War II, his wife, Alicia Syquia, and three of his five children were killed as they were fleeing their home.</p>

                            <p>After the war, Quirino continued public service, becoming president pro tempore of the Senate. In 1946, he was elected first vice president of the independent Republic of the Philippines, serving under Manuel Roxas. He also served as secretary of state.</p>

                            <span onmouseover = "start_scroll_up()"; onmouseout="stopscrolling";  id="up"><img src="images/arrow_up.png" /></span>
                    <span id="down" onmouseover="start_scroll_down()"; onmouseout="stopscrolling"; ><img src="images/arrow_down.png" /></span>
                    </div>
                </div>
            </div>

谢谢大家

我已经修改了您的代码并生成了一个工作示例。这是一个完整的html页面

<html><head> <title></title> </head> <body> <div id="content1" class="scrolling-content" style="height:100px;overflow-y:auto;"> <h2 style="font-size:30px;">Quirino's Story</h2> <p>Elpidio Quirino was a Filipino politician, and the sixth President of the Philippines.</p> <p>He was born in Vigan, Ilocos Sur to Mariano Quirino and Gregoria Rivera, Quirino spent his early years in Aringay, La Union. He received secondary education at Vigan High School, then went to Manila where he worked as junior computer in the Bureau of Lands and as property clerk in the Manila police department. He graduated from Manila High School in 1911 and also passed the civil service examination, first-grade.</p> <p>Quirino attended the University of the Philippines. In 1915, he earned his law degree from the university's College of Law, and was admitted to the bar later that year. He was engaged in the private practice of law until he was elected as member of the Philippine House of Representatives from 1919 to 1925, then as Senator from 1925 to 1931. He then served as Secretary of Finance and Secretary of the Interior in the Commonwealth government.</p> <p>In 1934, Quirino was a member of the Philippine Independence mission to Washington D.C., headed by Manuel L. Quezon that secured the passage in the United States Congress of the Tydings-McDuffie Act. This legislation set the date for Philippine independence by 1945. Official declaration came on July 4, 1946.</p> <p>During the Battle of Manila in World War II, his wife, Alicia Syquia, and three of his five children were killed as they were fleeing their home.</p> <p>After the war, Quirino continued public service, becoming president pro tempore of the Senate. In 1946, he was elected first vice president of the independent Republic of the Philippines, serving under Manuel Roxas. He also served as secretary of state.</p> </div> <span onmouseover = "startScrollUp();" onmouseout="stop_scrolling();"; id="up"><img src="images/arrow_up.png" /></span> <span id="down" onmouseover="startScrollDown();" onmouseout="stop_scrolling();" ><img src="images/arrow_down.png" /></span> <script type="text/javascript"> var UpdateInterval = 20; var PixelPerInterval = 2; var scrollInterval; function startScrollUp() { scrollInterval = setInterval(function(){scrollUp()}, UpdateInterval); } function startScrollDown() { scrollInterval = setInterval(function(){scrollDown()}, UpdateInterval); } function scrollDown() { document.getElementById('content1').scrollTop += PixelPerInterval; } function scrollUp() { document.getElementById('content1').scrollTop -= PixelPerInterval; } function stop_scrolling() { clearInterval(scrollInterval); } </script> </body> 基里诺的故事 埃尔皮迪奥·基里诺是菲律宾政治家,也是菲律宾第六任总统

他出生在维冈,马里亚诺·基里诺和格雷戈里亚·里维拉的伊洛科斯河畔,基里诺早年在巴黎度过 阿林盖,洛杉矶联盟。他在维甘高中接受中学教育,然后前往马尼拉,在该局担任初级计算机 作为马尼拉警察局的土地和财产文员。他1911年毕业于马尼拉高中,并通过了公务员制度 一年级考试

奎里诺就读于菲律宾国立大学。1915年,他获得了该大学法学学位 并于当年晚些时候获得律师资格。在当选为委员会成员之前,他一直从事私人执业 1919年至1925年担任菲律宾众议院议员,1925年至1931年担任参议员。他随后担任财政部长和财政部长 英联邦政府内政部长

1934年,基里诺是由曼努埃尔L。 确保美国国会通过Tydings-McDuffie法案的Quezon。这项立法规定了菲律宾加入世贸组织的日期 1945年独立。1946年7月4日正式宣布

在第二次世界大战的马尼拉战役中,他的妻子Alicia Syquia和五个孩子中的三个被杀 当他们逃离家园的时候

战后,基里诺继续为公众服务,成为参议院临时主席。1946年,他 当选菲律宾独立共和国第一副总统,在曼努埃尔·罗克萨斯手下任职。他还担任过秘书长 国家

var UpdateInterval=20; var PixelPerInterval=2; var间隔; 函数startScrollUp(){ scrollInterval=setInterval(函数(){scrollUp()},UpdateInterval); } 函数startsrolldown(){ scrollInterval=setInterval(函数(){scrollDown()},UpdateInterval); } 函数scrollDown(){ document.getElementById('content1').scrollTop+=PixelPerInterval; } 函数scrollUp(){ document.getElementById('content1').scrollTop-=PixelPerInterval; } 函数停止滚动(){ 清除间隔(滚动间隔); } 不过你很接近

干杯


安德鲁:-)

问题是什么???“我怎样才能激怒我的用户?”很高兴我能帮上忙。:-) <html><head> <title></title> </head> <body> <div id="content1" class="scrolling-content" style="height:100px;overflow-y:auto;"> <h2 style="font-size:30px;">Quirino's Story</h2> <p>Elpidio Quirino was a Filipino politician, and the sixth President of the Philippines.</p> <p>He was born in Vigan, Ilocos Sur to Mariano Quirino and Gregoria Rivera, Quirino spent his early years in Aringay, La Union. He received secondary education at Vigan High School, then went to Manila where he worked as junior computer in the Bureau of Lands and as property clerk in the Manila police department. He graduated from Manila High School in 1911 and also passed the civil service examination, first-grade.</p> <p>Quirino attended the University of the Philippines. In 1915, he earned his law degree from the university's College of Law, and was admitted to the bar later that year. He was engaged in the private practice of law until he was elected as member of the Philippine House of Representatives from 1919 to 1925, then as Senator from 1925 to 1931. He then served as Secretary of Finance and Secretary of the Interior in the Commonwealth government.</p> <p>In 1934, Quirino was a member of the Philippine Independence mission to Washington D.C., headed by Manuel L. Quezon that secured the passage in the United States Congress of the Tydings-McDuffie Act. This legislation set the date for Philippine independence by 1945. Official declaration came on July 4, 1946.</p> <p>During the Battle of Manila in World War II, his wife, Alicia Syquia, and three of his five children were killed as they were fleeing their home.</p> <p>After the war, Quirino continued public service, becoming president pro tempore of the Senate. In 1946, he was elected first vice president of the independent Republic of the Philippines, serving under Manuel Roxas. He also served as secretary of state.</p> </div> <span onmouseover = "startScrollUp();" onmouseout="stop_scrolling();"; id="up"><img src="images/arrow_up.png" /></span> <span id="down" onmouseover="startScrollDown();" onmouseout="stop_scrolling();" ><img src="images/arrow_down.png" /></span> <script type="text/javascript"> var UpdateInterval = 20; var PixelPerInterval = 2; var scrollInterval; function startScrollUp() { scrollInterval = setInterval(function(){scrollUp()}, UpdateInterval); } function startScrollDown() { scrollInterval = setInterval(function(){scrollDown()}, UpdateInterval); } function scrollDown() { document.getElementById('content1').scrollTop += PixelPerInterval; } function scrollUp() { document.getElementById('content1').scrollTop -= PixelPerInterval; } function stop_scrolling() { clearInterval(scrollInterval); } </script> </body>