当前位置: 编程技术>.net/c#/asp.net
Vb.net保持页面滚动条位置不变的实现代码
来源: 互联网 发布时间:2014-08-30
本文导语: 我们知道,在控制浏览器滚动条大多用Page.SmartNavigation = False,对于页面中DIV滚动条控制也是如此,具体应用参考如下的代码吧。 //代码1 Public Shared Sub SaveDivScrollPosition(ByVal divIDArray As String, ByVal objPage As Page) Dim saveScrollPosition A...
我们知道,在控制浏览器滚动条大多用Page.SmartNavigation = False,对于页面中DIV滚动条控制也是如此,具体应用参考如下的代码吧。
//代码1 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 = "" _ & "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;}" _ & "" objPage.RegisterStartupScript("saveScroll" & divID(i), saveScrollPosition) Next End Sub //代码2 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 = "" _ & setPositionFunction _ & "" 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]; } } }//by http://www. //在页面后台调用时的代码 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
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。