jQuery實(shí)現(xiàn)頁(yè)面滾動(dòng)時(shí)層智能浮動(dòng)定位實(shí)例探討
更新時(shí)間:2013年03月29日 18:04:35 作者:
在博客或者微博上面也會(huì)見(jiàn)到這個(gè)效果,所以客戶就也想要這樣的效果了,接下來(lái)為大家詳細(xì)介紹下浮動(dòng)定位實(shí)現(xiàn)的過(guò)程,感興趣的朋友可以參考下哈
各位兄弟可能碰到定位的問(wèn)題,特別是在博客或者微博上面也會(huì)見(jiàn)到這個(gè)效果,于是產(chǎn)品人員在策劃的時(shí)候就會(huì)要人家那種效果,,,而苦逼的我們需要去實(shí)現(xiàn),實(shí)現(xiàn)實(shí)現(xiàn)。。。。。沒(méi)辦法,誰(shuí)讓我們是攻城師呢,攻吧:
效果圖如下,滾動(dòng)條下拉的時(shí)候黑色的塊TOP為0;固定顯示:

代碼如下:
<!DOCTYPE html>
<html >
<head>
<title>jQuery實(shí)現(xiàn)頁(yè)面滾動(dòng)時(shí)層智能浮動(dòng)定位</title>
<meta name="description" content="" />
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<style type="text/css">
*{ margin:0; padding:0;}
.top{height:100px; background:#ccc;text-align:center; line-height:100px; font-size:40px;}
body { font:12px/1.8 Arial; color:#666; height:2000px;}
.float{width:200px; height:200px; border:1px solid #ffecb0; background-color:#000;position:absolute; right:10px; top:150px;}
</style>
</head>
<body>
<div class="top">導(dǎo)航啊導(dǎo)航啊導(dǎo)航</div>
<div class="float" id="float"></div>
<script type="text/javascript">
$.fn.smartFloat = function() {
var position = function(element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top: 0
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: pos,
top: top
});
}
});
};
return $(this).each(function() {
position($(this));
});
};
//綁定
$("#float").smartFloat();
</script>
</div>
</body>
</html>
效果圖如下,滾動(dòng)條下拉的時(shí)候黑色的塊TOP為0;固定顯示:

代碼如下:
復(fù)制代碼 代碼如下:
<!DOCTYPE html>
<html >
<head>
<title>jQuery實(shí)現(xiàn)頁(yè)面滾動(dòng)時(shí)層智能浮動(dòng)定位</title>
<meta name="description" content="" />
<script type="text/javascript" src="http://jt.875.cn/js/jquery.js"></script>
<style type="text/css">
*{ margin:0; padding:0;}
.top{height:100px; background:#ccc;text-align:center; line-height:100px; font-size:40px;}
body { font:12px/1.8 Arial; color:#666; height:2000px;}
.float{width:200px; height:200px; border:1px solid #ffecb0; background-color:#000;position:absolute; right:10px; top:150px;}
</style>
</head>
<body>
<div class="top">導(dǎo)航啊導(dǎo)航啊導(dǎo)航</div>
<div class="float" id="float"></div>
<script type="text/javascript">
$.fn.smartFloat = function() {
var position = function(element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function() {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.css({
position: "fixed",
top: 0
});
} else {
element.css({
top: scrolls
});
}
}else {
element.css({
position: pos,
top: top
});
}
});
};
return $(this).each(function() {
position($(this));
});
};
//綁定
$("#float").smartFloat();
</script>
</div>
</body>
</html>
相關(guān)文章
jQuery實(shí)現(xiàn)簡(jiǎn)單的手風(fēng)琴效果
這篇文章主要為大家詳細(xì)介紹了jQuery實(shí)現(xiàn)簡(jiǎn)單的手風(fēng)琴效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-06-06jQuery遍歷DOM的父級(jí)元素、子級(jí)元素和同級(jí)元素的方法總結(jié)
借助jQuery我們可以輕松地堆DOM元素進(jìn)行向上、向下遍歷以及同級(jí)的遍歷,本文我們即來(lái)整理jQuery遍歷DOM的父級(jí)元素、子級(jí)元素和同級(jí)元素的方法總結(jié):2016-07-07jquery select 設(shè)置默認(rèn)選中的示例代碼
本篇文章主要是對(duì)jquery select 設(shè)置默認(rèn)選中的示例代碼進(jìn)行了介紹,需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助2014-02-02JQuery寫(xiě)動(dòng)態(tài)樹(shù)示例代碼
本文為大家介紹下使用JQuery寫(xiě)的動(dòng)態(tài)樹(shù),具體實(shí)現(xiàn)如下,感興趣的朋友可以學(xué)習(xí)下2013-07-07基于JQuery的浮動(dòng)DIV顯示提示信息并自動(dòng)隱藏
浮動(dòng)DIV定時(shí)顯示提示信息,如操作成功, 失敗等,需要的朋友可以參考下。2011-02-02瘋狂Jquery第一天(Jquery學(xué)習(xí)筆記)
之前一直學(xué)習(xí),現(xiàn)在終于有時(shí)間來(lái)整理一下文檔了。以下文章都是自己學(xué)習(xí)Jquery 的筆記,希望能留下痕跡,也希望能幫助到您2012-05-05