Jquery 固定悬浮层以及固定表头
2014-12-16 14:13
120 查看
/* =========================================================== * jquery.autofix_anything.js v1 * =========================================================== * Copyright 2013 Pete Rojwongsuriya. * http://www.thepetedesign.com * * Fix position of anything on your website automatically * with one js call * * https://github.com/peachananr/autofix_anything * * ========================================================== */ !function($){ var defaults = { customOffset: false, manual: false, onlyInContainer: true }; $.fn.autofix_anything = function(options){ var settings = $.extend({}, defaults, options), el = $(this), curpos = el.position(), offset = settings.customOffset, pos = el.offset(); el.addClass("autofix_sb") $.fn.manualfix = function() { var el = $(this), pos = el.offset(); if (el.hasClass("fixed")) { el.removeClass("fixed") } else { el.addClass("fixed").css({ top: 0, left: pos.left, right: "auto", bottom: "auto" }); } } fixAll = function(el, settings, curpos, pos){ if (settings.customOffset == false) offset = el.parent().offset().top if($(document).scrollTop() > offset && $(document).scrollTop() <= (el.parent().height() + (offset - $(window).height()))) { el.removeClass("bottom").addClass("fixed").css({ top: 0, left: pos.left, right: "auto", bottom: "auto" }); } else { if($(document).scrollTop() > offset) { if (settings.onlyInContainer == true ) { if($(document).scrollTop() > (el.parent().height() - $(window).height())) { el.addClass("bottom fixed").removeAttr( 'style' ).css({ left: curpos.left }); }else { el.removeClass("bottom fixed").removeAttr( 'style' ); } } } else { el.removeClass("bottom fixed").removeAttr( 'style' ); } } } if (settings.manual == false) { $(window).scroll(function() { fixAll(el, settings, curpos, pos) }); } } }(window.jQuery);
.autofix_sb.fixed { position: fixed !important; left: auto; top: auto; right: auto; bottom: auto; height: 100%; overflow:auto;
<script type="text/javascript"> $(document).ready( function() { $(".sidebar").autofix_anything(); }); </script>
} .autofix_sb.fixed.bottom { bottom: 0; position: absolute !important; }
相关文章推荐
- 利用jQuery实现GridView固定表头
- 基于jquery的表头固定的若干方法
- 冻结 锁定 固定 行 列 表头 抬头 html table jquery 全兼容常见浏览器
- jQuery制作多表格固定表头、切换表头的特效
- jQuery,Table表头固定插件chromatable存在的问题及解决办法
- jQuery - 综合实例 - 固定表头,滚动表格内容
- jquery.fixedtableheader.min.js固定表头功能
- JQuery实现fixed固定div--同固定表头
- jQuery实现表头固定效果的实例代码
- 表头固定(利用jquery实现原理介绍)
- 利用JQuery实现固定表头,兼容IE7/8 & FF
- 基于jquery的固定表头和列头的代码
- Jquery固定表头插件,兼容IE6.7.8.9 ,Chrome ,FF
- Jquery插件 -- 表格固定表头
- TABLE 多表头固定问题(基本jquery插件)
- jQuery_固定行表头列表头表格插件
- 冻结 锁定 固定 行 列 表头 抬头 html table jquery 全兼容常见浏览
- Jquery实现相对浏览器位置固定、悬浮
- jquery固定表头方法
- jquery固定表头不滚动让内容滚动的代码实现