forked from alstjq88/smashthewindow.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
33 lines (30 loc) · 1012 Bytes
/
script.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
$(function(){
$window = $(window);
$body = $("body");
$bgBlur = $(".bg-blur");
var bgBlurHeight = $bgBlur.height();
var scrollFlag = false;
var scrollThreshold = 0.25;
var blurWhenReach = 3;
$window.on("scroll", function(event){
var scrollTop = $window.scrollTop();
if(!scrollFlag){
scrollFlag = true;
$body.addClass("disable-pointer-events");
}
debouncePointerEvents();
if(scrollTop < bgBlurHeight){
var _alpha = (scrollTop / bgBlurHeight) * blurWhenReach;
if(_alpha > 1){ _alpha = 1 }
TweenMax.set($bgBlur, {alpha: _alpha });
}
});
function debouncePointerEvents(){
TweenMax.killDelayedCallsTo(addPointerEvents);
TweenMax.delayedCall(scrollThreshold, addPointerEvents);
}
function addPointerEvents(){
scrollFlag = false;
$body.removeClass("disable-pointer-events");
}
});