源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

capacityFixed 基于jquery的类似于新浪微博新消息提示的定位框

  • 时间:2022-01-15 22:32 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:capacityFixed 基于jquery的类似于新浪微博新消息提示的定位框
效果图: [img]http://files.jb51.net/upload/201105/20110524231235903.jpg[/img] 当浏览器滚动的时候,要浮层要移除浏览器界面视区的时候,修改其position属性,让其浮动在窗口的上沿显示就可以了,position:fixed,可以在IE7+和其他浏览器下浮动层平滑固定定位,由于IE6前辈不支持fixed属性,使用position:absolute属性代替,重新计算top值。 具体代码如下: HTML代码:
[url=http://www.1sucai.cn/]<p id="WB_unread_msg_1303891276972">10条新消息,<a href="http://www.1sucai.cn/">查看消息</a></p> <p id="WB_unread_msg_1303891276973">108个新粉丝,<a href="http://www.1sucai.cn/">查看粉丝</a></p> <a href="#" title="关闭" id="" class="close-ico">关闭</a> </div>
CSS代码: JS代码:
[u]复制代码[/u] 代码如下:
/** * @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);
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部