forked from bfl-itp/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.scrollmagic.debug.js
More file actions
executable file
·251 lines (237 loc) · 8.01 KB
/
jquery.scrollmagic.debug.js
File metadata and controls
executable file
·251 lines (237 loc) · 8.01 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/*
ScrollMagic v1.1.2
The jQuery plugin for doing magical scroll interactions.
(c) 2014 Jan Paepke (@janpaepke)
License & Info: http://janpaepke.github.io/ScrollMagic
Inspired by and partially based on SUPERSCROLLORAMA by John Polacek (@johnpolacek)
http://johnpolacek.github.com/superscrollorama/
Powered by the Greensock Tweening Platform (GSAP): http://www.greensock.com/js
Greensock License info at http://www.greensock.com/licensing/
*/
/*
@overview Debug Extension for ScrollMagic.
@version 1.1.2
@license Dual licensed under MIT license and GPL.
@author Jan Paepke - e-mail@janpaepke.de
*/
(function($, ScrollScene) {
/**
* Add Indicators for a ScrollScene.
* __REQUIRES__ ScrollMagic Debug Extension: `jquery.scrollmagic.debug.js`
* The indicators can only be added _AFTER_ the scene has been added to a controller.
* @public
* @example
* // add basic indicators
* scene.addIndicators()
*
* // passing options
* scene.addIndicators({zindex: 100, colorEnd: "#FFFFFF"});
*
* @param {object} [options] - An object containing one or more options for the indicators.
* @param {(string|object)} [options.parent=undefined] - A selector, DOM Object or a jQuery object that the indicators should be added to.
If undefined, the scene's container will be used.
* @param {number} [options.zindex=-1] - CSS zindex for the indicator container.
* @param {number} [options.indent=0] - Additional position offset for the indicators (useful, when having multiple scenes starting at the same time).
* @param {number} [options.suffix=""] - This string will be attached to the start and end indicator (useful for identification when working with multiple scenes).
* @param {string} [options.colorTrigger=blue] - CSS color definition for the trigger indicator.
* @param {string} [options.colorStart=green] - CSS color definition for the start indicator.
* @param {string} [options.colorEnd=red] - CSS color definition for the end indicator.
*/
ScrollScene.prototype.addIndicators = function(opt) {
var
DEFAULT_OPTIONS = {
parent: undefined,
zindex: -1,
indent: 0,
suffix: "",
colorTrigger: "blue",
colorStart: "green",
colorEnd: "red"
};
var
scene = this,
options = $.extend({}, DEFAULT_OPTIONS, opt),
controller = this.parent();
if (controller) {
var
cParams = controller.info(),
suffix = (options.labelSuffix === "") ? "" : " " + options.suffix,
$container = $(options.parent).length > 0 ?
$(options.parent)
: cParams.isDocument ? $("body") : cParams.container, // check if window element (then use body)
$wrap = $("<div></div>")
.addClass("ScrollSceneIndicators")
.data("options", options)
.css({
position: "absolute",
top: 0,
left: 0,
width: "100%",
height: "100%",
"text-align": "center",
"z-index": options.zindex,
"pointer-events": "none",
"font-size": 10
}),
$triggerHook = $("<div>trigger</div>")
.css({
position: "fixed",
overflow: "visible",
color: options.colorTrigger
})
.addClass("hook");
$start = $("<div>start" + suffix + "</div>")
.css({
position: "absolute",
overflow: "visible",
color: options.colorStart
})
.addClass("start");
$end = $("<div>end" + suffix + "</div>")
.css({
position: "absolute",
overflow: "visible",
color: options.colorEnd
})
.addClass("end");
if ($container.css("position") == "static") {
$container.css("position", "relative"); // positioning needed for correct display of indicators
}
scene.indicators = $wrap
.append($triggerHook)
.append($start)
.append($end)
.appendTo($container);
scene.updateIndicators();
var callUpdate = function (e) {
if ((e.type == "scroll" || e.type == "resize") && !cParams.isDocument) {
scene.updateIndicators(true);
} else {
scene.updateIndicators();
}
};
scene.on("change.debug", callUpdate);
cParams.container.on("resize scroll", callUpdate);
if (!cParams.isDocument) {
$(window).on("scroll resize", callUpdate);
}
} else {
console.log("ERROR: Please add Scene to controller before adding indicators.");
}
return scene;
};
ScrollScene.prototype.updateIndicators = function(triggerOnly) {
var
scene = this,
controller = scene.parent(),
indicators = scene.indicators,
options = indicators.data("options");
if (indicators && controller) {
var
cParams = controller.info(),
$triggerHook = indicators.children(".hook"),
$start = indicators.children(".start"),
$end = indicators.children(".end"),
parentOffset = cParams.container.offset() || {top: 0, left: 0},
parentPos = cParams.vertical ? parentOffset.top : parentOffset.left,
hookPos = (cParams.size * scene.triggerHook()) + parentPos,
direction = cParams.vertical ? "v" : "h";
if (cParams.isDocument) { // account for possible body positioning
var bodyOffset = indicators.offsetParent().is("body") ? $("body").offset() : parentOffset;
indicators.css({
top: -bodyOffset.top,
left: -bodyOffset.left
});
} else {
hookPos -= cParams.vertical ? $(document).scrollTop() : $(document).scrollLeft();
}
$triggerHook
.attr("data-hook", hookPos)
.attr("data-direction", direction)
.data("parent", cParams.container);
$otherhook = $(".ScrollSceneIndicators .hook[data-hook=\""+ hookPos +"\"][data-direction="+direction+"]:visible").not($triggerHook);
if ($otherhook.length > 0 && $otherhook.data("parent") == cParams.container) {
$triggerHook.hide();
} else {
$triggerHook.show();
var flip = hookPos > cParams.size*0.8; // put name above line?
if (cParams.vertical) {
// triggerHook
$triggerHook.css({
top: flip ? hookPos - $triggerHook.height() - 2 : hookPos,
left: (cParams.isDocument ? cParams.container.width() : parentOffset.left + cParams.container.width() - $(document).scrollLeft()) - 70 - options.indent,
width: 40,
height: "auto",
padding: "0 8px 2px 8px",
"border-top": flip ? "none" : "1px solid blue",
"border-bottom": flip ? "1px solid blue" : "none",
"border-left": "none",
"border-right": "none"
});
} else {
$triggerHook.css({
top: (cParams.isDocument ? cParams.container.height() : parentOffset.top + cParams.container.height() - $(document).scrollTop()) - 40 - options.indent,
left: flip ? hookPos - $triggerHook.width() - 9: hookPos,
width: "auto",
height: 20,
padding: "5px 5px 0 5px",
"border-top": "none",
"border-bottom": "none",
"border-left": flip ? "none" : "1px solid blue",
"border-right": flip ? "1px solid blue" : "none"
});
}
}
if (!triggerOnly) {
var
startPos = scene.triggerPosition(),
endPos = startPos + scene.duration(),
resetCSS = {
"border": "none",
top: "auto",
bottom: "auto",
left: "auto",
right: "auto"
};
$start.css(resetCSS);
$end.css(resetCSS);
if (scene.duration() === 0) {
$end.hide();
} else {
$end.show();
}
if (cParams.vertical) {
// start
$start.css({
top: startPos,
right: 71-cParams.container.scrollLeft() + options.indent,
"border-top": "1px solid green",
padding: "0 8px 0 8px"
});
// end
$end.css({
top: endPos,
right: 71-cParams.container.scrollLeft() + options.indent,
"border-top": "1px solid red",
padding: "0 8px 0 8px"
});
} else {
// start
$start.css({
left: startPos,
bottom: 40-cParams.container.scrollTop() + options.indent,
"border-left": "1px solid green",
padding: "0 8px 0 8px"
});
// end
$end.css({
left: endPos,
bottom: 40-cParams.container.scrollTop() + options.indent,
"border-left": "1px solid red",
padding: "0 8px 0 8px"
});
}
}
}
};
})(jQuery, ScrollScene);