滚动条定位控制

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

        
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 >
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值