asp.net 頁面逐步呈現的方法總結

來源:互聯網
上載者:User

詳細介紹,請參考:flush 讓頁面分塊,逐步呈現
假設有一個頁面,一開始顯示 cnblogs 的 logo 表徵圖,3 秒鐘後顯示 csdn 的 logo 表徵圖。

我根據上文介紹,用 asp.net 實現了上述功能。
ASP.NET 代碼如下: 複製代碼 代碼如下:<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="flush讓頁面分塊逐步呈現.aspx.cs" Inherits="Web_1.flush讓頁面分塊逐步呈現" %>
<!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讓頁面分塊逐步呈現</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 秒後載入下面內容...
<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>

如果想實現 tudou.com 首頁圖片消極式載入的效果,則可以使用 jquery 輕鬆實現。
詳細介紹,請參考:名站技術分析 - 淺談 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;">
一開始看不到下面的圖片,滾動滑鼠後可以看見:
<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>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.