Skip to content

Commit 9b5767b

Browse files
committed
added more types for "offset" option
1 parent 1ad4306 commit 9b5767b

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ as well as (overridden) for each individually:
116116
All options are **optional**.
117117

118118
#### offset
119-
**Type:** number
119+
**Type:** number or string (percentage or viewport units) or callback function
120120
**Default:** 0
121121

122-
If you need to start the scene exact pixels from document's beginning or "triggerElement"'s beginning.
122+
If you need to start the scene after document's beginning or "triggerElement"'s beginning.
123123

124124
#### duration
125125
**Type:** number or string (percentage or viewport units) or callback function

jquery.data-parallax.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
typeof options.start === "undefined" || (options.triggerElement = options.start);
7272
typeof options.trigger == "undefined" || (options.triggerHook = options.trigger);
7373

74-
typeof options.offset === "number" || (options.offset = 0);
74+
typeof options.offset != "undefined" || (options.offset = 0);
7575
typeof options.triggerElement === "undefined" || (options.triggerElement = convertToElement(options.triggerElement));
7676
typeof options.triggerElement != "undefined" || (options.triggerElement = this[0]);
7777
optionsArr.push(options);
@@ -291,9 +291,10 @@
291291
this.$el = $el;
292292
this.from = options.from;
293293
this.to = options.to;
294-
this.offset = options.offset;
295294
this.axis = options.axis;
296295

296+
this.offset = convertOption(options.offset, this.getElementDimension());
297+
297298
typeof options.triggerHook != "undefined" || (options.triggerHook = "100%");
298299
this.triggerHook = convertOption(options.triggerHook, options.axis === Scene.AXIS_X ? windowWidth : windowHeight);
299300
this.triggerElement = convertToElement(options.triggerElement);
@@ -338,14 +339,18 @@
338339
};
339340
}
340341
else {
341-
var maxDuration = this.axis === Scene.AXIS_X ? this.$el.outerWidth() : this.$el.outerHeight(),
342-
durationPx = convertOption(duration, maxDuration);
342+
var durationPx = convertOption(duration, this.getElementDimension());
343343
validateDurationPx(durationPx);
344344
this.duration = function () {
345345
return durationPx;
346346
};
347347
}
348348
},
349+
getElementDimension: function() {
350+
return this.axis === Scene.AXIS_X ?
351+
this.$el.outerWidth(true) :
352+
this.$el.outerHeight(true);
353+
},
349354
needsUpdate: function() {
350355
this.updateStart();
351356
this.updateDuration();

0 commit comments

Comments
 (0)