无为清净楼资源网 Design By www.qnjia.com
一般来说很多的人在控制浏览器滚动条都是用Page.SmartNavigation = False,对于页面中DIV等等的滚动条控制,我在看了别人代码后,写了一个,仅供参考:
复制代码 代码如下:
Public Shared Sub SaveDivScrollPosition(ByVal divIDArray As String, ByVal objPage As Page)
Dim saveScrollPosition As String
Dim i As Integer
Dim divID() As String
divID = divIDArray.Split(",")
For i = 0 To divID.Length - 1
objPage.RegisterHiddenField(divID(i) & "__SCROLLPOS", objPage.Request.Form(divID(i) & "__SCROLLPOS"))
saveScrollPosition = "<script language='javascript'>" _
& "function saveScrollPosition() {" _
& " if (document.all['" & divID(i) & "'] != undefined) {" _
& "document.forms[0]." & divID(i) & "__SCROLLPOS.value = " _
& "document.all['" & divID(i) & "'].scrollTop + ',' " _
& " + document.all['" & divID(i) & "'].scrollLeft;}}" _
& "if (document.all['" & divID(i) & "'] != undefined) {document.all['" & divID(i) & "'].onscroll=saveScrollPosition;}" _
& "</script>"
objPage.RegisterStartupScript("saveScroll" & divID(i), saveScrollPosition)
Next
End Sub
复制代码 代码如下:
Public Shared Sub RestoreDivScrollPosition(ByVal divIDArray As String, ByVal objPage As Page)
Dim restoreScrollPosition As String
Dim setPositionFunction As String
Dim i As Integer
Dim divID() As String
divID = divIDArray.Split(",")
For i = 0 To divID.Length - 1
setPositionFunction = setPositionFunction & "SetScrollPosition('" & divID(i) & "');"
Next
restoreScrollPosition = "<script language='javascript'>" _
& setPositionFunction _
& "</script>"
objPage.RegisterStartupScript("restoreScroll", restoreScrollPosition)
End Sub
JAVASCRIPT:
复制代码 代码如下:
function SetScrollPosition(divID){
var e;
var a;
var obj;
if (document.getElementById(divID)){
obj = eval('document.forms[0].' + divID + '__SCROLLPOS');
if (obj) {
e=eval('document.forms[0].' + divID + '__SCROLLPOS').value;
a=e.split(',');
document.getElementById(divID).scrollTop= a[0];
document.getElementById(divID).scrollLeft= a[1];
}
}
}
在页面后台调用的时候,写下如下的代码:
复制代码 代码如下:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
call SaveDivScrollPosition("div1,div2,div3",me)
call RestoreDivScrollPosition("div1,div2,div3",me)
End Sub
不好意思,这两个SUB可以写成一个,仅供参考。
复制代码 代码如下:
Public Shared Sub SaveDivScrollPosition(ByVal divIDArray As String, ByVal objPage As Page)
Dim saveScrollPosition As String
Dim i As Integer
Dim divID() As String
divID = divIDArray.Split(",")
For i = 0 To divID.Length - 1
objPage.RegisterHiddenField(divID(i) & "__SCROLLPOS", objPage.Request.Form(divID(i) & "__SCROLLPOS"))
saveScrollPosition = "<script language='javascript'>" _
& "function saveScrollPosition() {" _
& " if (document.all['" & divID(i) & "'] != undefined) {" _
& "document.forms[0]." & divID(i) & "__SCROLLPOS.value = " _
& "document.all['" & divID(i) & "'].scrollTop + ',' " _
& " + document.all['" & divID(i) & "'].scrollLeft;}}" _
& "if (document.all['" & divID(i) & "'] != undefined) {document.all['" & divID(i) & "'].onscroll=saveScrollPosition;}" _
& "</script>"
objPage.RegisterStartupScript("saveScroll" & divID(i), saveScrollPosition)
Next
End Sub
复制代码 代码如下:
Public Shared Sub RestoreDivScrollPosition(ByVal divIDArray As String, ByVal objPage As Page)
Dim restoreScrollPosition As String
Dim setPositionFunction As String
Dim i As Integer
Dim divID() As String
divID = divIDArray.Split(",")
For i = 0 To divID.Length - 1
setPositionFunction = setPositionFunction & "SetScrollPosition('" & divID(i) & "');"
Next
restoreScrollPosition = "<script language='javascript'>" _
& setPositionFunction _
& "</script>"
objPage.RegisterStartupScript("restoreScroll", restoreScrollPosition)
End Sub
JAVASCRIPT:
复制代码 代码如下:
function SetScrollPosition(divID){
var e;
var a;
var obj;
if (document.getElementById(divID)){
obj = eval('document.forms[0].' + divID + '__SCROLLPOS');
if (obj) {
e=eval('document.forms[0].' + divID + '__SCROLLPOS').value;
a=e.split(',');
document.getElementById(divID).scrollTop= a[0];
document.getElementById(divID).scrollLeft= a[1];
}
}
}
在页面后台调用的时候,写下如下的代码:
复制代码 代码如下:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
call SaveDivScrollPosition("div1,div2,div3",me)
call RestoreDivScrollPosition("div1,div2,div3",me)
End Sub
不好意思,这两个SUB可以写成一个,仅供参考。
标签:
滚动条,位置
无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com
暂无评论...
更新日志
2024年11月15日
2024年11月15日
- 第五街的士高《印度激情版》3CD [WAV+CUE][2.4G]
- 三国志8重制版哪个武将智力高 三国志8重制版智力武将排行一览
- 三国志8重制版哪个武将好 三国志8重制版武将排行一览
- 三国志8重制版武将图像怎么保存 三国志8重制版武将图像设置方法
- 何方.1990-我不是那种人【林杰唱片】【WAV+CUE】
- 张惠妹.1999-妹力新世纪2CD【丰华】【WAV+CUE】
- 邓丽欣.2006-FANTASY【金牌大风】【WAV+CUE】
- 饭制《黑神话》蜘蛛四妹手办
- 《燕云十六声》回应跑路:年内公测版本完成95%
- 网友发现国内版《双城之战》第二季有删减:亲亲环节没了!
- 邓丽君2024-《漫步人生路》头版限量编号MQA-UHQCD[WAV+CUE]
- SergeProkofievplaysProkofiev[Dutton][FLAC+CUE]
- 永恒英文金曲精选4《TheBestOfEverlastingFavouritesVol.4》[WAV+CUE]
- 群星《国风超有戏 第9期》[320K/MP3][13.63MB]
- 群星《国风超有戏 第9期》[FLAC/分轨][72.56MB]