Showing
1 changed file
with
34 additions
and
0 deletions
public/js/plugin/sticky.js
0 → 100644
1 | +/** | ||
2 | + * Module: sticky | ||
3 | + * Desc: 滚动固定 | ||
4 | + * @author: xuan.chen@yoho.cn | ||
5 | + */ | ||
6 | + | ||
7 | +'use strict'; | ||
8 | + | ||
9 | +var Sticky = function(elem, options) { | ||
10 | + this.options = $.extend({}, Sticky.DEAFAULT, options); | ||
11 | + this.$elem = $(elem); | ||
12 | + this.$holder = $('<div></div>').height(this.$elem.height()); | ||
13 | + this.$target = $(this.options.target) | ||
14 | + .on('scroll.yoho.sticky', $.proxy(this.checkPosition, this)); | ||
15 | + | ||
16 | + this.$elem.wrapper(this.$holder); | ||
17 | + | ||
18 | + this.checkPosition(); | ||
19 | +}; | ||
20 | + | ||
21 | +Sticky.DEAFAULT = { | ||
22 | + top: 0, // offset top, 距离附着元素的位移 | ||
23 | + target: window // 附着元素 | ||
24 | +}; | ||
25 | + | ||
26 | +Sticky.prototype.checkPosition = function() { | ||
27 | + if (!this.$elem.is('::visible')) { | ||
28 | + return; | ||
29 | + } | ||
30 | +}; | ||
31 | + | ||
32 | + | ||
33 | + | ||
34 | +module.exports = Sticky; |
-
Please register or login to post a comment