drupalexp-sticky.js
1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
(function ($) {
$.fn.dexpsticky = function (e) {
this.each(function () {
var b = $(this);
b.addClass('dexp-sticky');
b.data('offset-top', b.data('offset-top') || b.offset().top);
b.data('max-height', b.outerHeight());
var c = $('<div>').addClass('sticky-wrapper').height(b.outerHeight());
b.wrap(c);
var d = b.parents('.sticky-wrapper');
setInterval(function () {
//if($(window).width()<992) return;
d.height(b.outerHeight());
b.width(d.width());
}, 50);
$(window).bind('scroll',function () {
if($(window).width()<992) return;
var a = $(window).scrollTop();
if (a > b.data('offset-top')) {
b.addClass('fixed');
setTimeout(function () {
b.addClass('fixed-transition')
}, 10);
} else {
b.removeClass('fixed');
setTimeout(function () {
b.removeClass('fixed-transition')
}, 10);
}
}).bind('resize',function () {
b.removeClass('fixed fixed-transition').data('offset-top', b.offset().top);
$(window).scroll();
}).scroll();
});
};
$(window).load(function () {
$('.dexp-sticky').dexpsticky()
})
}(jQuery));