会员
周边
众包
新闻
博问
闪存
赞助商
Chat2DB
所有博客
当前博客
我的博客
我的园子
账号设置
会员中心
简洁模式
...
退出登录
注册
登录
小山
付出最大努力,追求最高成就,享受最佳生活,收获无悔人生
博客园
首页
新随笔
联系
订阅
管理
公告
滚动条定位控制
using
System;
using
System.Collections;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Web;
using
System.Web.SessionState;
using
System.Web.UI;
using
System.Web.UI.WebControls;
using
System.Web.UI.HtmlControls;
using
System.Data.SqlClient;
namespace
Document
{
/**/
///
<summary>
///
Summary description for WebForm5.
///
</summary>
public
class
WebForm5 : System.Web.UI.Page
{
protected
System.Web.UI.WebControls.Button Button2;
protected
System.Web.UI.WebControls.TextBox pos;
Web Form Designer generated code
#region
Web Form Designer generated code
override
protected
void
OnInit(EventArgs e)
{
InitializeComponent();
base
.OnInit(e);
}
private
void
InitializeComponent()
{
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
}
#endregion
private
void
Page_Load(
object
sender, System.EventArgs e)
{
}
protected
string
writebutton()
{
string
script
=
""
;
script
=
"
<table>
"
;
for
(
int
m
=
0
;m
<
100
;m
++
)
{
script
+=
"
<tr><td>
"
;
script
+=
m;
script
+=
"
</td></tr>
"
;
}
script
+=
"
</table>
"
;
return
script;
}
}
}
1.窗体自身滚动条定位控制
<
HTML
>
<
HEAD
>
<
title
>
窗体自身滚动条定位控制
</
title
>
<
meta
content
="Microsoft Visual Studio .NET 7.1"
name
="GENERATOR"
>
<
meta
content
="C#"
name
="CODE_LANGUAGE"
>
<
meta
content
="JavaScript"
name
="vs_defaultClientScript"
>
<
meta
content
="http://schemas.microsoft.com/intellisense/ie5"
name
="vs_targetSchema"
>
<
SCRIPT
type
="text/javascript"
>
<!--
function
onscrollform()
{
document.all[
"
pos
"
].value
=
document.body.scrollTop;
}
function
formOnload()
{
OnloadForScroll();
}
function
OnloadForScroll()
{
var
spos
=
document.all[
"
pos
"
].value;
window.scrollTo(
0
, spos );
}
-->
</
SCRIPT
>
</
HEAD
>
<
BODY
onscroll
="onscrollform();"
onload
="formOnload();"
scroll
="yes"
ms_positioning
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<%
=
writebutton()
%>
<
asp:textbox
id
="pos"
style
="DISPLAY: none"
Runat
="server"
></
asp:textbox
>
<
asp:Button
id
="Button2"
style
="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px"
runat
="server"
Text
="可以将页面缩小,把滚动条往下拉看效果"
></
asp:Button
>
</
form
>
</
FORM
>
</
BODY
>
</
HTML
>
2.窗体自身滚动条被禁止,而通过div的滚动条来定位控制
<
HTML
>
<
HEAD
>
<
title
>
窗体自身滚动条被禁止,而通过div的滚动条来定位控制
</
title
>
<
meta
content
="Microsoft Visual Studio .NET 7.1"
name
="GENERATOR"
>
<
meta
content
="C#"
name
="CODE_LANGUAGE"
>
<
meta
content
="JavaScript"
name
="vs_defaultClientScript"
>
<
meta
content
="http://schemas.microsoft.com/intellisense/ie5"
name
="vs_targetSchema"
>
<
SCRIPT
type
="text/javascript"
>
<!--
function
scrollDiv()
{
document.all.pos.value
=
document.all.onlinediv.scrollTop;
//
onlinediv是一个div
}
function
formOnload()
{
OnloadForScroll();
}
function
OnloadForScroll()
{
var
spos
=
document.all[
"
pos
"
].value;
if
(
!
spos)spos
=
0
;
document.all.onlinediv.scrollTop
=
spos;
}
-->
</
SCRIPT
>
</
HEAD
>
<
BODY
onscroll
="onscrollform();"
onload
="formOnload();"
scroll
="no"
ms_positioning
="GridLayout"
>
<
form
id
="Form1"
method
="post"
runat
="server"
>
<
table
width
="300"
>
<
tr
>
<
td
>
<
div
id
="onlinediv"
style
="OVERFLOW: auto; WIDTH: 100%; HEIGHT: 560px"
onscroll
="scrollDiv();"
>
<%
=
writebutton()
%>
</
div
>
</
td
>
</
tr
>
</
table
>
<
asp:textbox
id
="pos"
style
="DISPLAY: none"
Runat
="server"
></
asp:textbox
>
<
asp:Button
id
="Button2"
style
="Z-INDEX: 102; LEFT: 336px; POSITION: absolute; TOP: 520px"
runat
="server"
Text
="可以将页面缩小,把滚动条往下拉看效果"
></
asp:Button
>
</
form
>
</
FORM
>
</
BODY
>
</
HTML
>
posted on
2005-10-18 14:54
小山
阅读(
7259
) 评论(
16
)
编辑
收藏
举报
刷新页面
返回顶部
Powered by:
博客园
Copyright © 2025 小山
Powered by .NET 9.0 on Kubernetes