DIV CSS 佈局教程網

 DIV+CSS佈局教程網 >> 網頁腳本 >> JavaScript入門知識 >> jQuery入門知識 >> JQuery特效代碼 >> capacityFixed 基於jquery的類似於新浪微博新消息提示的定位框
capacityFixed 基於jquery的類似於新浪微博新消息提示的定位框
編輯:JQuery特效代碼     
效果圖:

當浏覽器滾動的時候,要浮層要移除浏覽器界面視區的時候,修改其position屬性,讓其浮動在窗口的上沿顯示就可以了,position:fixed,可以在IE7+和其他浏覽器下浮動層平滑固定定位,由於IE6前輩不支持fixed屬性,使用position:absolute屬性代替,重新計算top值。
具體代碼如下:
HTML代碼:
代碼如下:
<div class="float" id="float">
<p id="WB_unread_msg_1303891276971">1條新私信,<a href="http://www.poluoluo.com/">查看私信</a></p>
<p id="WB_unread_msg_1303891276972">10條新消息,<a href="http://www.poluoluo.com/">查看消息</a></p>
<p id="WB_unread_msg_1303891276973">108個新粉絲,<a href="http://www.poluoluo.com/">查看粉絲</a></p>
<a href="#" title="關閉" id="" class="close-ico">關閉</a>
</div>

CSS代碼:
代碼如下:
.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; background-image:url(img/close-ico.png); text-indent:-900px; overflow:hidden; }
.float .close-ico:hover{ background-position:0 -16px;}
.float p{ line-height:22px}

JS代碼:
代碼如下:
/**
* @author 愚人碼頭
* 類似於新浪微博新消息提示的定位框
* 更多
*/
(function($){
$.fn.capacityFixed = function(options) {
var opts = $.extend({},$.fn.capacityFixed.deflunt,options);

var FixedFun = function(element) {
var top = opts.top;
var right = ($(window).width()-opts.pageWidth)/2+opts.right;
element.css({
"right":right,
"top":top
});
$(window).resize(function(){
var right = ($(window).width()-opts.pageWidth)/2+opts.right;
element.css({
"right":right
});
});
$(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: "absolute",
top: top
});
}
});
element.find(".close-ico").click(function(event){
element.remove();
event.preventDefault();
})
};
return $(this).each(function() {
FixedFun($(this));
});
};
$.fn.capacityFixed.deflunt={
right : 100,//相對於頁面寬度的右邊定位
top:100,
pageWidth : 960
};
})(jQuery);
XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved