欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

ASP.NET jQuery 實(shí)例9  通過控件hyperlink實(shí)現(xiàn)返回頂部效果

 更新時(shí)間:2012年02月03日 16:57:49   作者:  
ASP.NET jQuery 實(shí)例9 通過控件hyperlink實(shí)現(xiàn)返回頂部效果的實(shí)現(xiàn)代碼,需要的朋友可以參考下
要實(shí)現(xiàn)該效果,首先要先了解以下幾點(diǎn)基礎(chǔ)知識(shí):
窗體滾動(dòng)事件:$(window).scroll(function(){...});
獲取窗體滾動(dòng)距離:$(window).scrollTop();
獲取窗體高度:$(window).height();
了解以上內(nèi)容就可以實(shí)現(xiàn)通過hyperlink控件實(shí)現(xiàn)返回頂部的效果了。
1.準(zhǔn)備界面結(jié)構(gòu)代碼:
復(fù)制代碼 代碼如下:

<form id="form1" runat="server">
<div>
<asp:HyperLink ID="Top" runat="server"></asp:HyperLink>
<h1 style="text-align: center">
利用jQuery實(shí)現(xiàn)返回頂部效果</h1>
<div style="width: 800px; border: 1px; text-align: left; margin-left: 230px;">
。。。。。。(很多內(nèi)容,可以滾動(dòng))
</div>
<asp:HyperLink ID="backToTopLink" runat="server" CssClass="backToTop">回頂部</asp:HyperLink>
</div>
</form>

2.給回頂部控件添加樣式:
復(fù)制代碼 代碼如下:

<style type="text/css">
.backToTop
{
background-color: Yellow;
width: 30px;
border-style: outset;
border-width: 1px;
text-align: center;
font-weight: bold;
font-family: Arial;
font-size: x-large;
cursor: pointer;
position:absolute; // 注意要設(shè)置為絕對(duì)位置
right: 100px;
}
</style>

3.添加實(shí)現(xiàn)置頂效果腳本代碼:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
$(document).ready(function () {
$("#backToTopLink").attr("title", "回頂部");
$("#backToTopLink").attr("href", "#Top"); // 通過鏈接實(shí)現(xiàn)置頂
$(window).scroll(function () {
if ($(window).scrollTop() <= 100) {
$("#backToTopLink").fadeOut(200);
}
else {
$("#backToTopLink").fadeIn(400);
}
var v_Top = $(window).height() - $(".backToTop").height() - 10 + $(window).scrollTop(); // 動(dòng)態(tài)計(jì)算滾動(dòng)后置頂按鈕top位置
$(".backToTop").css("top", v_Top + "px");
});
});
</script>

注意,本代碼只是為了演示hyperlink控件來實(shí)現(xiàn)返回頂部的效果。還可以通過jQuery的動(dòng)畫效果,實(shí)現(xiàn)平滑置頂。
平滑過渡返回頂部代碼如下:
$('#backToTopLink').click(function(){$('html,body').animate({scrollTop: '0px'}, 800);}); // 替換$("#backToTopLink").attr("href", "#Top");即可

相關(guān)文章

最新評(píng)論