-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallaxScroll.js
61 lines (48 loc) · 1.85 KB
/
parallaxScroll.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**
* Very alpha. use at own risk!
*/
(function (jQuery) {
var scroll = 0;
var msecs = new Date().getTime();
var scrolling = false;
var timer = null;
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
function eventbinder(options) {
var self = this;
jQuery(document).on('scroll touchmove',function() {
if(is_chrome) {
clearTimeout(timer);
if (scrolling == false) {
msecs = new Date().getTime();
}
scrolling = true;
var eventfired = new Date().getTime();
var csstime = eventfired-msecs;
scroll = window.pageYOffset;
msecs = eventfired;
timer = setTimeout(function() {
scrolling = false;
}, 1000);
}
var calc = "center " + parseInt(-window.pageYOffset / 4) + "px !important";
var calc2 = (-window.pageYOffset / 2.5) + "px !important";
if(is_chrome) {
calc += "; transition : background-position " + (csstime) + "ms;";
calc2 += "; transition : margin-top " + (csstime) + "ms";
}
jQuery(self).css("cssText", "background-position :" + calc);
jQuery(self).find("div").css("cssText", "margin-top :" + calc2);
});
}
jQuery.fn.parallaxScroll = function (options, parameter) {
if (typeof(options) === "string") return Query.fn.parallaxScroll.methods[options](this, parameter);
return this.each(function () {
console.log(this);
var options = jQuery.extend(true, {}, options);
jQuery.data(this, 'options', {
options: options
});
eventbinder.call(this, options);
});
};
})(jQuery);