asp.net 頁面逐步呈現(xiàn)的方法總結(jié)
更新時間:2010年06月23日 12:26:34 作者:
分塊編碼 ( chunked encoding )就是讓 response 分塊編碼進(jìn)行傳輸。response 分塊編碼,可以先傳輸一部分不需要處理的 html 代碼到客戶端,等其他耗時代碼執(zhí)行完畢后再傳輸另外的 html 代碼。
詳細(xì)介紹,請參考:flush 讓頁面分塊,逐步呈現(xiàn)
假設(shè)有一個頁面,一開始顯示 cnblogs 的 logo 圖標(biāo),3 秒鐘后顯示 csdn 的 logo 圖標(biāo)。
我根據(jù)上文介紹,用 asp.net 實現(xiàn)了上述功能。
ASP.NET 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="flush讓頁面分塊逐步呈現(xiàn).aspx.cs" Inherits="Web_1.flush讓頁面分塊逐步呈現(xiàn)" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>flush讓頁面分塊逐步呈現(xiàn)</title>
</head>
<body>
<div id="head" style="border:1px solid #ccc;">
cnblogs logo <img src="http://images.cnblogs.com/logo_small.gif" alt=""/>
</div>
<%
// flush分塊輸出
Response.BufferOutput = false;
Response.Flush();
// Response.Output.Flush();
%>
<br /> 3 秒后加載下面內(nèi)容...
<div id="content" style="border:1px solid blue;">
<%
// 睡眠3秒
System.Threading.Thread.Sleep(3000);
%>
csdn logo <img src="http://csdnimg.cn/www/images/csdnindex_piclogo.gif" alt=""/>
</div>
</body>
</html>
如果想實現(xiàn) tudou.com 首頁圖片延遲加載的效果,則可以使用 jquery 輕松實現(xiàn)。
詳細(xì)介紹,請參考:名站技術(shù)分析 - 淺談 tudou.com 首頁圖片延遲加載的效果
JQuery 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
一開始能看到的圖片:
<img src="http://at-img4.tdimg.com/board/2010/5/tylc-115X55.jpg"/>
<div id="lazyBox" style="margin-top:100px;">
一開始看不到下面的圖片,滾動鼠標(biāo)后可以看見:
<img width="120" height="90" style="border:1px solid blue;" class="lazyImg" alt="http://i01.img.tudou.com/data/imgs/i/051/871/396/m20.jpg" src="http://css.tudouui.com/skin/__g/img/sprite.gif" coords="_DBA"/>
</div>
<div style="height:1000px;"></div>
<script type="text/javascript">
var hasShow = false;
$(window).bind("scroll",function(){
if(hasShow==true){
$(window).unbind("scroll");
return;
}
var t = $(document).scrollTop();
if(t>50){
// 滾動高度超過50,加載圖片
hasShow = true;
$("#lazyBox .lazyImg").each(function(){
$(this).attr("src",$(this).attr("alt"));
});
}
});
</script>
</body>
</html>
假設(shè)有一個頁面,一開始顯示 cnblogs 的 logo 圖標(biāo),3 秒鐘后顯示 csdn 的 logo 圖標(biāo)。
我根據(jù)上文介紹,用 asp.net 實現(xiàn)了上述功能。
ASP.NET 代碼如下:
復(fù)制代碼 代碼如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="flush讓頁面分塊逐步呈現(xiàn).aspx.cs" Inherits="Web_1.flush讓頁面分塊逐步呈現(xiàn)" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>flush讓頁面分塊逐步呈現(xiàn)</title>
</head>
<body>
<div id="head" style="border:1px solid #ccc;">
cnblogs logo <img src="http://images.cnblogs.com/logo_small.gif" alt=""/>
</div>
<%
// flush分塊輸出
Response.BufferOutput = false;
Response.Flush();
// Response.Output.Flush();
%>
<br /> 3 秒后加載下面內(nèi)容...
<div id="content" style="border:1px solid blue;">
<%
// 睡眠3秒
System.Threading.Thread.Sleep(3000);
%>
csdn logo <img src="http://csdnimg.cn/www/images/csdnindex_piclogo.gif" alt=""/>
</div>
</body>
</html>
如果想實現(xiàn) tudou.com 首頁圖片延遲加載的效果,則可以使用 jquery 輕松實現(xiàn)。
詳細(xì)介紹,請參考:名站技術(shù)分析 - 淺談 tudou.com 首頁圖片延遲加載的效果
JQuery 代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>
</head>
<body>
一開始能看到的圖片:
<img src="http://at-img4.tdimg.com/board/2010/5/tylc-115X55.jpg"/>
<div id="lazyBox" style="margin-top:100px;">
一開始看不到下面的圖片,滾動鼠標(biāo)后可以看見:
<img width="120" height="90" style="border:1px solid blue;" class="lazyImg" alt="http://i01.img.tudou.com/data/imgs/i/051/871/396/m20.jpg" src="http://css.tudouui.com/skin/__g/img/sprite.gif" coords="_DBA"/>
</div>
<div style="height:1000px;"></div>
<script type="text/javascript">
var hasShow = false;
$(window).bind("scroll",function(){
if(hasShow==true){
$(window).unbind("scroll");
return;
}
var t = $(document).scrollTop();
if(t>50){
// 滾動高度超過50,加載圖片
hasShow = true;
$("#lazyBox .lazyImg").each(function(){
$(this).attr("src",$(this).attr("alt"));
});
}
});
</script>
</body>
</html>
您可能感興趣的文章:
- asp.net Server.MapPath方法注意事項
- 充分利用ASP.NET的三種緩存提高站點性能的注意方法
- 調(diào)試ASP.NET應(yīng)用程序的方法和技巧
- ASP.NET技巧:數(shù)據(jù)島出到Excel最為簡易的方法
- .net與javascript腳本的交互方法總結(jié)
- ASP.NET過濾HTML字符串方法總結(jié)
- Asp.net禁用頁面緩存的方法總結(jié)
- Asp.Net alert彈出提示信息的幾種方法總結(jié)
- asp.net刷新本頁面的六種方法總結(jié)
- asp.net中幾種常用的身份驗證方法總結(jié)
- ASP.NET 頁面?zhèn)髦党S梅椒偨Y(jié)
- .NET中方法的注意事項總結(jié)
相關(guān)文章
.NET實現(xiàn)WebSocket服務(wù)端即時通信實例
本篇文章主要介紹了.NET實現(xiàn)即時通信,WebSocket服務(wù)端實例 ,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02
asp.net使用JS+form表單Post和Get方式提交數(shù)據(jù)
今天小編就為大家分享一篇關(guān)于asp.net使用JS+form表單Post和Get方式提交數(shù)據(jù),小編覺得內(nèi)容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧2019-01-01
設(shè)置ASP.NET頁面的運行超時時間詳細(xì)到單個頁面及站點
這篇文章主要介紹了如何設(shè)置ASP.NET頁面的運行超時時間,包括全局超時時間、單個站點超時時間、單個頁面請求超時時間,需要的朋友可以參考下2014-06-06
關(guān)于.NET Attribute在數(shù)據(jù)校驗中的應(yīng)用教程
這篇文章主要給大家介紹了關(guān)于.NET Attribute在數(shù)據(jù)校驗中的應(yīng)用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用.NET具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05
Visual Studio ASP.NET Core MVC入門教程第一篇
這篇文章主要為大家詳細(xì)介紹了Visual Studio ASP.NET Core MVC入門教程的第一篇,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03

