Skip to content

Commit a055272

Browse files
committed
added class property
1 parent c6bfef2 commit a055272

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ Using the object syntax you can explicitly pass in a **from** value (optional),
6060

6161
Make an elements' position fixed during the scene.
6262

63+
#### class
64+
**Type** string
65+
66+
Adds one or more classes to the element during the scene.
67+
6368
#### x
6469
**Type:** number
6570

jquery.data-parallax.js

+28-6
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@
181181
var pinOptions = mergeOptions(options.pin, globalOptions);
182182
animation.pin = new PinScene($this, pinOptions);
183183
}
184+
if (typeof options.class != "undefined") {
185+
var classOptions = mergeOptions(options.class, globalOptions);
186+
animation.class = new ClassScene($this, classOptions);
187+
}
184188
animations.push(animation);
185189
}
186190
return animations;
@@ -472,6 +476,8 @@
472476
this._setFrom(this._getOldValue(style));
473477
this._setValue(this._getNewValue(), style);
474478
},
479+
_getOldValue: function() {},
480+
_getNewValue: function() {},
475481
_setFrom: function(defaultValue) {
476482
typeof this.from != "undefined" || (this.from = defaultValue);
477483
}
@@ -529,11 +535,31 @@
529535
}
530536
});
531537

538+
function StateScene($el, options) {
539+
typeof options.triggerHook != "undefined" || (options.triggerHook = 0);
540+
Scene.call(this, $el, options);
541+
}
542+
StateScene.prototype = inherit(Scene.prototype, {
543+
_needsUpdate: function() {
544+
return (typeof this.prevState != "undefined" || this.state == Scene.STATE_DURING) &&
545+
this.prevState != this.state;
546+
}
547+
});
548+
549+
function ClassScene($el, options) {
550+
StateScene.call(this, $el, options);
551+
}
552+
ClassScene.prototype = inherit(Scene.prototype, {
553+
_setValue: function() {
554+
this.$el[this.state == Scene.STATE_DURING ? 'addClass' : 'removeClass'](this.to);
555+
}
556+
});
557+
532558
function PinScene($el, options) {
533559
options.to = convertToElement(options.to);
534560
isElement(options.to) || (options.to = $el[0]);
535561
typeof options.triggerHook != "undefined" || (options.triggerHook = 0);
536-
Scene.call(this, $el, options);
562+
StateScene.call(this, $el, options);
537563
PinScene.scenes.push(this);
538564
}
539565
PinScene.scenes = [];
@@ -545,16 +571,12 @@
545571
}
546572
}
547573
};
548-
PinScene.prototype = inherit(Scene.prototype, {
574+
PinScene.prototype = inherit(StateScene.prototype, {
549575
updateStart: function() {
550576
if (this.state != Scene.STATE_DURING) {
551577
Scene.prototype.updateStart.call(this);
552578
}
553579
},
554-
_needsUpdate: function() {
555-
return (typeof this.prevState != "undefined" || this.state == Scene.STATE_DURING) &&
556-
this.prevState != this.state;
557-
},
558580
_getOldValue: function(style) {
559581
var toStyle = getComputedStyle(this.to);
560582
return {

0 commit comments

Comments
 (0)