<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery实现页面滚动时层智能浮动定位小插件</title>
<style type="text/css">
*{ margin:0; padding:0;}
body { font:12px/1.8 Arial; color:#666;}
h1.tit-h1 { font-size:38px; text-align:center; margin:30px 0 15px; color:#f60;}
.go-back{ text-align:center; border-top:1px dashed #ccc; padding:10px; margin-top:20px; font-size:40px;}
.wrap{border:1px dashed #ccc; background:#f8f8f8; padding:20px;}
.demo { height:1500px; }
.float { width:200px; padding:5px 10px; border:1px solid #ffecb0; font-size:12px; background-color:#fffee0; -moz-box-shadow:1px 1px 2px rgba(0,0,0,.2); -webkit-box-shadow:1px 1px 2px rgba(0,0,0,.2); box-shadow:1px 1px 2px rgba(0,0,0,.2); position:absolute; -moz-border-radius:5px; -webkit-border-radius:5px; border-radius:5px; }
.float .close-ico{ position:absolute; top:5px; right:5px; display:block; width:16px; height:16px; }
</style>
<script type="text/javascript" src="http://www.lizhoumin.com/js.js"></script>
</head>
<body>
<h1 class="tit-h1">jQuery实现页面滚动时层智能浮动定位</h1>
<div style="width:960px; margin:0 auto;"><p style="font-size:20px; color:#f00; background:#000; color:#fff; text-align:center; font-weight:800;">与别人分享快乐,你的快乐就会加倍,与别人分担痛苦,你的痛苦就会减半。</p></div>
<div class="wrap">
<script type="text/javascript">
(class="tags" href="/tags/FUNCTION.html" title=function>function($){
$.fn.capacityFixed = class="tags" href="/tags/FUNCTION.html" title=function>function(options) {
var opts = $.extend({},$.fn.capacityFixed.deflunt,options);
var FixedFun = class="tags" href="/tags/FUNCTION.html" title=function>function(element) {
var top = opts.top;
var right = ($(window).width()-opts.pageWidth)/2+opts.right;
element.css({
"right":right,
"top":top
});
$(window).resize(class="tags" href="/tags/FUNCTION.html" title=function>function(){
var right = ($(window).width()-opts.pageWidth)/2+opts.right;
element.css({
"right":right
});
});
$(window).scroll(class="tags" href="/tags/FUNCTION.html" title=function>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: "absolute",
top: top
});
}
});
element.find(".close-ico").click(class="tags" href="/tags/FUNCTION.html" title=function>function(event){
element.remove();
event.preventDefault();
})
};
return $(this).each(class="tags" href="/tags/FUNCTION.html" title=function>function() {
FixedFun($(this));
});
};
$.fn.capacityFixed.deflunt={
right : 100,//相对于页面宽度的右边定位
top:150,
pageWidth : 960
};
})(jQuery);
</script>
<div class="float" id="float">
<p>1条新私信,<a href="http://www.lizhoumin.com/">查看私信</a></p>
<p>10条新消息,<a href="http://www.lizhoumin.com/">查看消息</a></p>
<p>108个新粉丝,<a href="http://www.lizhoumin.com/">查看粉丝</a></p>
<a href="#" title="关闭" id="" class="close-ico">关闭</a>
</div>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<p>哥是来占位的</p>
<script type="text/javascript">
$("#float").capacityFixed();
</script>
</div>
<div style="height:500px;"></div>
</body>
</html>