强制滚动< div>? [英] Force scroll on a <div>?

查看:68
本文介绍了强制滚动< div>?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在div中显示HTML文本,并打开页面滚动到底部的
。 (我的div有溢出:自动,所以它出现滚动条)


我发现这适用于textarea:


文件.all.MyDivId.scrollTop = document.all.MyDivId] .scrollHeight;


但这对div不起作用。我正在使用div,因为我显示的文本包含HTML。当然可以简单地设置一个滚动条

到div的底部???谢谢!

解决方案

Simon Wigzell写道:

我想在div中显示HTML文本并打开页面到底部。 (我的div有溢出:auto以便它显示滚动条)

我发现这适用于textarea:

document.all.MyDivId.scrollTop = document .all.MyDivId] .scrollHeight;


不,它不会,你只是认为它。

但是这对div不起作用。我正在使用div,因为我显示的文本包含HTML。当然可以简单地设置一个滚动条
到div的底部???谢谢!




是的,可能。


-

兰迪

comp.lang.javascript常见问题 - http://jibbering.com/faq


Simon Wigzell写道:

我想在div中显示HTML文本,并打开页面滚动到底部。 (我的div有溢出:auto以便它显示滚动条)

我发现这适用于textarea:

document.all.MyDivId.scrollTop = document .all.MyDivId] .scrollHeight;

但是这对div不起作用。我正在使用div,因为我显示的文本包含HTML。当然可以简单地设置一个滚动条
到div的底部???谢谢!




它也不适用于任何不支持微软的b $ b专有文档的浏览器。所有。


为什么锚不会工作?


-

Rob


Simon Wigzell写道:

我想在div中显示HTML文本,并将页面打开
滚动到底部。 (我的div有溢出:auto所以它出现滚动
吧)
我发现这适用于textarea:

document.all.MyDivId.scrollTop = document .all.MyDivId] .scrollHeight;

但是这对div不起作用。我正在使用div,因为显示的文本I
包含HTML。当然可以简单地在div中将
滚动条设置到底部???谢谢!




试试这个...


< script type =" text / javascript">


函数scrollDiv()

{

var el;

if((el = document.getElementById (''MyDivId''))

&&(''undefined''!= typeof el.scrollTop))

{

el.scrollTop = 0;

el.scrollTop = 5000;

}

}


window.onload = scrollDiv;


< / script>


I want to display HTML text inside a div and have the page open scrolled to
the bottom. (My div has overflow:auto so that it appears with scroll bars)

I have found this that works on a textarea:

document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;

But this doesn''t work on a div. I am using a div because the text I am
displaying contains HTML. Surely it is possible to simply set a scroll bar
to the bottom in a div??? Thanks!

解决方案

Simon Wigzell wrote:

I want to display HTML text inside a div and have the page open scrolled to
the bottom. (My div has overflow:auto so that it appears with scroll bars)

I have found this that works on a textarea:

document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;
No it doesn''t, you just think it does.
But this doesn''t work on a div. I am using a div because the text I am
displaying contains HTML. Surely it is possible to simply set a scroll bar
to the bottom in a div??? Thanks!



Yep, its possible.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq


Simon Wigzell wrote:

I want to display HTML text inside a div and have the page open scrolled to
the bottom. (My div has overflow:auto so that it appears with scroll bars)

I have found this that works on a textarea:

document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;

But this doesn''t work on a div. I am using a div because the text I am
displaying contains HTML. Surely it is possible to simply set a scroll bar
to the bottom in a div??? Thanks!



Nor will it work in any browser that doesn''t support Microsoft''s
proprietary document.all.

Why wont an anchor work?

--
Rob


Simon Wigzell wrote:

I want to display HTML text inside a div and have the page open scrolled to the bottom. (My div has overflow:auto so that it appears with scroll bars)
I have found this that works on a textarea:

document.all.MyDivId.scrollTop = document.all.MyDivId].scrollHeight;

But this doesn''t work on a div. I am using a div because the text I am displaying contains HTML. Surely it is possible to simply set a scroll bar to the bottom in a div??? Thanks!



Try this...

<script type="text/javascript">

function scrollDiv()
{
var el;
if ((el = document.getElementById(''MyDivId''))
&& (''undefined'' != typeof el.scrollTop))
{
el.scrollTop = 0;
el.scrollTop = 5000;
}
}

window.onload = scrollDiv;

</script>


这篇关于强制滚动&lt; div&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆