直接上代码
$.fn.smartFloat = function (className) {
var position = function (element) {
var top = element.position().top, pos = element.css("position");
$(window).scroll(function () {
var scrolls = $(this).scrollTop();
if (scrolls > top) {
if (window.XMLHttpRequest) {
element.addClass(className);
} else {
element.removeClass(className);
}
} else {
element.removeClass(className);
}
});
};
return $(this).each(function () {
position($(this));
});
};
.fixed {
position: fixed;
top: 0;
z-index: 10;
990px;
-webkit-box-shadow: 0 4px 4px rgba(0,0,0,.1);
-moz-box-shadow: 0 4px 4px rgba(0,0,0,.1);
box-shadow: 0 4px 4px rgba(0,0,0,.1);
}
//选择要加载的层和要加载的样式
$(".filters").smartFloat("fixed");