jQuery實(shí)現(xiàn)仿新浪微博浮動(dòng)的消息提示框(可智能定位)
本文實(shí)例講述了jQuery實(shí)現(xiàn)仿新浪微博浮動(dòng)的消息提示框。分享給大家供大家參考。具體如下:
這是一款jQuery實(shí)現(xiàn)的仿新浪微博新消息提示框效果,支持智能浮動(dòng)定位框,新浪微博用來(lái)提示消息時(shí)候的智能定位框,可以適時(shí)關(guān)閉窗口,你完全可以將其應(yīng)用到你網(wǎng)頁(yè)的其它地方。
運(yùn)行效果截圖如下:

在線演示地址如下:
http://demo.jb51.net/js/2015/js-f-sina-weibo-info-dlg-demo/
具體代碼如下:
<!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>
<title>仿新浪微博新消息提示的智能浮動(dòng)定位框</title>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<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;}
/* Head Fixed */
.fixed-top{position:fixed;bottom:auto;top:0px;}
/* Foot Fixed */
.fixed-bottom{position:fixed;bottom:0px;top:auto;}
/* Left Fixed */
.fixed-left{position:fixed;right:auto;left:0px;}
/* RIGHT Fixed */
.fixed-right{position:fixed;right:0px;left:auto;}
* html,* html body{background-attachment:fixed;}
/* IE6 Head Fixed */
* html .fixed-top{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop));}
/* IE6 RIGHT Fixed */
* html .fixed-right{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft+document.documentElement.clientWidth-this.offsetWidth)-(parseInt(this.currentStyle.marginLeft,10)||0)-(parseInt(this.currentStyle.marginRight,10)||0));}
/* IE6 Foot Fixed */
* html .fixed-bottom{position:absolute;bottom:auto;top:expression(eval(document.documentElement.scrollTop+document.documentElement.clientHeight-this.offsetHeight-(parseInt(this.currentStyle.marginTop,10)||0)-(parseInt(this.currentStyle.marginBottom,10)||0)));}
/* IE6 Left Fixed */
* html .fixed-left{position:absolute;right:auto;left:expression(eval(document.documentElement.scrollLeft));}
</style>
<script type="text/javascript" src="jquery-1.6.2.min.js"></script>
<script type="text/javascript">
/**
* @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,//相對(duì)于頁(yè)面寬度的右邊定位
top:150,
pageWidth : 960
};
})(jQuery);
</script>
</head>
<body>
<div style="height:2000px;"></div>
<div class="wrap">
<div class="float" id="float">
<p>1條新私信,<a href="#">查看私信</a></p>
<p>108個(gè)新粉絲,<a href="#">查看粉絲</a></p>
<a href="#" title="關(guān)閉" id="" class="close-ico">×</a>
</div>
</div>
<script type="text/javascript">
$("#float").capacityFixed();
</script>
</body>
</html>
希望本文所述對(duì)大家的jQuery程序設(shè)計(jì)有所幫助。
- JS模擬Dialog彈出浮動(dòng)框效果代碼
- JavaScript實(shí)現(xiàn)的浮動(dòng)層框架用法實(shí)例分析
- jQuery實(shí)現(xiàn)的登錄浮動(dòng)框效果代碼
- 基于jquery的一個(gè)浮動(dòng)框(擴(kuò)展性比較好 )
- 在js(jquery)中獲得文本框焦點(diǎn)和失去焦點(diǎn)的方法
- 九種js彈出對(duì)話框的方法總結(jié)
- js中判斷文本框是否為空的兩種方法
- js限制文本框只能輸入數(shù)字方法小結(jié)
- js監(jiān)聽輸入框值的即時(shí)變化onpropertychange、oninput
- 簡(jiǎn)單實(shí)現(xiàn)js浮動(dòng)框
相關(guān)文章
jQuery.extend 與 jQuery.fn.extend的用法及區(qū)別實(shí)例分析
這篇文章主要介紹了jQuery.extend 與 jQuery.fn.extend的用法及區(qū)別,結(jié)合實(shí)例形式分析了jQuery.extend與jQuery.fn.extend的功能、使用方法及區(qū)別,需要的朋友可以參考下2018-07-07
jquery實(shí)現(xiàn)移動(dòng)端懸浮拖拽框
這篇文章主要為大家詳細(xì)介紹了jquery實(shí)現(xiàn)移動(dòng)端懸浮拖拽框,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
jquery實(shí)現(xiàn)(textarea)placeholder自動(dòng)換行
本文主要對(duì)jquery如何實(shí)現(xiàn)(textarea) placeholder自動(dòng)換行的方法、思路進(jìn)行介紹,下面就跟小編一起來(lái)看下吧2016-12-12
使用jQuery實(shí)現(xiàn)購(gòu)物車結(jié)算功能
這篇文章主要為大家詳細(xì)介紹了使用jQuery實(shí)現(xiàn)購(gòu)物車結(jié)算功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08
jQuery 連續(xù)列表實(shí)現(xiàn)代碼
你有沒有手工的編寫過(guò)一些重復(fù)的代碼?你也覺得它們是如此的無(wú)聊吧。好了,這里有更好的解決辦法。2009-12-12
JQuery拖動(dòng)表頭邊框線調(diào)整表格列寬效果代碼
當(dāng)鼠標(biāo)停留在表頭邊框線上,接著拖動(dòng)鼠標(biāo),會(huì)在表格中出現(xiàn)一條隨鼠標(biāo)移動(dòng)的豎線,最后放開鼠標(biāo),表格列寬會(huì)被調(diào)整2014-09-09
jquery xMarquee實(shí)現(xiàn)文字水平無(wú)縫滾動(dòng)效果
這篇文章主要介紹了jquery xMarquee實(shí)現(xiàn)文字水平無(wú)縫滾動(dòng)效果,需要的朋友可以參考下2014-04-04
Enter回車切換輸入焦點(diǎn)實(shí)現(xiàn)思路與代碼兼容各大瀏覽器
這篇文章主要介紹了Enter回車切換輸入焦點(diǎn)實(shí)現(xiàn)思路與代碼并兼容各大瀏覽器,需要的朋友可以參考下2014-09-09
jQuery模擬原生態(tài)App上拉刷新下拉加載更多頁(yè)面及原理
很多App中,新聞或者展示類都存在下拉刷新和上拉加載的效果,如何實(shí)現(xiàn)上拉刷新下拉加載更多頁(yè)面的呢?下面小編通過(guò)下面內(nèi)容給大家介紹jQuery模擬原生態(tài)App上拉刷新下拉加載更多頁(yè)面及原理,需要的朋友可以參考下2015-08-08

