Skip to content

Commit ebec071

Browse files
committed
ScrollReveal v4.0.0-beta.27
1 parent 61e04de commit ebec071

File tree

4 files changed

+145
-179
lines changed

4 files changed

+145
-179
lines changed

dist/scrollreveal.es.js

Lines changed: 71 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*! @license ScrollReveal v4.0.0-beta.26
1+
/*! @license ScrollReveal v4.0.0-beta.27
22
33
Copyright 2018 Fisssion LLC.
44
@@ -18,6 +18,7 @@ var defaults = {
1818
distance: '0',
1919
duration: 600,
2020
easing: 'cubic-bezier(0.6, 0.2, 0.1, 1)',
21+
interval: 0,
2122
opacity: 0,
2223
origin: 'bottom',
2324
rotate: {
@@ -26,6 +27,7 @@ var defaults = {
2627
z: 0
2728
},
2829
scale: 1,
30+
cleanup: true,
2931
container: document.documentElement,
3032
desktop: true,
3133
mobile: true,
@@ -540,7 +542,7 @@ function registerCallbacks(element, isDelayed) {
540542
clock: window.setTimeout(function () {
541543
afterCallback(element.node);
542544
element.callbackTimer = null;
543-
if (element.revealed && !element.config.reset) {
545+
if (element.revealed && !element.config.reset && element.config.cleanup) {
544546
clean.call(this$1, element.node);
545547
}
546548
}, duration - elapsed)
@@ -562,79 +564,72 @@ function sequence(element, pristine) {
562564
return animate.call(this, element, { reset: true })
563565
}
564566

565-
var store = this.store;
566-
var seq = store.sequences[element.sequence.id];
567+
var seq = this.store.sequences[element.sequence.id];
567568
var i = element.sequence.index;
568569

569570
if (seq) {
570-
var visible = new SequenceModel(seq, 'visible', store);
571-
var revealed = new SequenceModel(seq, 'revealed', store);
571+
var visible = new SequenceModel(seq, 'visible', this.store);
572+
var revealed = new SequenceModel(seq, 'revealed', this.store);
572573

573574
seq.models = { visible: visible, revealed: revealed };
574575

575576
/**
576-
* At any given time, the sequencer
577-
* needs to find these 3 elements:
578-
*/
579-
var currentElement;
580-
var nextHeadElement;
581-
var nextFootElement;
582-
583-
/**
584-
* When no elements within a sequence are revealed,
585-
* these 3 elements are easily pulled from the
586-
* current visible sequence model.
577+
* If the sequence has no revealed members,
578+
* then we reveal the first visible element
579+
* within that sequence.
580+
*
581+
* The sequence then cues a recursive call
582+
* in both directions.
587583
*/
588584
if (!revealed.body.length) {
589-
currentElement = getElement(seq, visible.body.shift(), store);
590-
nextHeadElement = getElement(seq, visible.head.pop(), store);
591-
nextFootElement = getElement(seq, visible.body.shift(), store);
592-
} else {
593-
/**
594-
* More typically though, something will be revealed
595-
* and we need to model the unrevealed elements.
596-
*/
597-
var unrevealed = {
598-
head: visible.body.filter(function (x) { return revealed.head.indexOf(x) >= 0; }),
599-
foot: visible.body.filter(function (x) { return revealed.foot.indexOf(x) >= 0; })
600-
};
601-
/**
602-
* Now we can compare the current sequence index
603-
* against our new model to determine the current element.
604-
*/
605-
if (!seq.blocked.head && i === [].concat( unrevealed.head ).pop()) {
606-
currentElement = getElement(seq, unrevealed.head.pop(), store);
607-
} else if (!seq.blocked.foot && i === [].concat( unrevealed.foot ).shift()) {
608-
currentElement = getElement(seq, unrevealed.foot.shift(), store);
585+
var nextId = seq.members[visible.body[0]];
586+
var nextElement = this.store.elements[nextId];
587+
588+
if (nextElement) {
589+
cue.call(this, seq, visible.body[0], -1, pristine);
590+
cue.call(this, seq, visible.body[0], +1, pristine);
591+
return animate.call(this, nextElement, { reveal: true, pristine: pristine })
609592
}
610-
/**
611-
* And the next head and foot elements are
612-
* easily pulled from our custom unrevealed model.
613-
*/
614-
nextHeadElement = getElement(seq, unrevealed.head.pop(), store);
615-
nextFootElement = getElement(seq, unrevealed.foot.shift(), store);
616593
}
617594

618595
/**
619-
* Verify and animate!
596+
* If our element isn’t resetting, we check the
597+
* element sequence index against the head, and
598+
* then the foot of the sequence.
620599
*/
621-
if (currentElement) {
622-
if (nextHeadElement) { cue.call(this, seq, nextHeadElement, 'head', pristine); }
623-
if (nextFootElement) { cue.call(this, seq, nextFootElement, 'foot', pristine); }
624-
return animate.call(this, currentElement, { reveal: true, pristine: pristine })
600+
if (
601+
!seq.blocked.head &&
602+
i === [].concat( revealed.head ).pop() &&
603+
i >= [].concat( visible.body ).shift()
604+
) {
605+
cue.call(this, seq, i, -1, pristine);
606+
return animate.call(this, element, { reveal: true, pristine: pristine })
607+
}
608+
609+
if (
610+
!seq.blocked.foot &&
611+
i === [].concat( revealed.foot ).shift() &&
612+
i <= [].concat( visible.body ).pop()
613+
) {
614+
cue.call(this, seq, i, +1, pristine);
615+
return animate.call(this, element, { reveal: true, pristine: pristine })
625616
}
626617
}
627618
}
628619

629620
function Sequence(interval) {
630-
this.id = nextUniqueId();
631-
this.interval = interval;
632-
this.members = [];
633-
this.models = {};
634-
this.blocked = {
635-
head: false,
636-
foot: false
637-
};
621+
if (Math.abs(interval) < 16) {
622+
throw new RangeError('Sequence interval must be at least 16.')
623+
} else {
624+
this.id = nextUniqueId();
625+
this.interval = Math.abs(interval);
626+
this.members = [];
627+
this.models = {};
628+
this.blocked = {
629+
head: false,
630+
foot: false
631+
};
632+
}
638633
}
639634

640635
function SequenceModel(seq, prop, store) {
@@ -665,21 +660,23 @@ function SequenceModel(seq, prop, store) {
665660
}
666661
}
667662

668-
function cue(seq, element, direction, pristine) {
663+
function cue(seq, i, direction, pristine) {
669664
var this$1 = this;
670665

671-
seq.blocked[direction] = true;
666+
var blocked = ['head', null, 'foot'][1 + direction];
667+
var nextId = seq.members[i + direction];
668+
var nextElement = this.store.elements[nextId];
669+
670+
seq.blocked[blocked] = true;
671+
672672
setTimeout(function () {
673-
seq.blocked[direction] = false;
674-
sequence.call(this$1, element, pristine);
673+
seq.blocked[blocked] = false;
674+
if (nextElement) {
675+
sequence.call(this$1, nextElement, pristine);
676+
}
675677
}, seq.interval);
676678
}
677679

678-
function getElement(seq, index, store) {
679-
var id = seq.members[index];
680-
return store.elements[id]
681-
}
682-
683680
function initialize() {
684681
var this$1 = this;
685682

@@ -749,31 +746,17 @@ function deepAssign(target) {
749746
}
750747
}
751748

752-
function reveal(target, options, interval, sync) {
749+
function reveal(target, options, syncing) {
753750
var this$1 = this;
754-
755-
/**
756-
* The reveal method has optional 2nd and 3rd parameters,
757-
* so we first explicitly check what was passed in.
758-
*/
759-
if (typeof options === 'number') {
760-
interval = parseInt(options);
761-
options = {};
762-
} else {
763-
interval = parseInt(interval);
764-
options = options || {};
765-
}
751+
if ( options === void 0 ) options = {};
752+
if ( syncing === void 0 ) syncing = false;
766753

767754
var containerBuffer = [];
768755
var sequence$$1;
769756

770757
try {
771-
if (interval) {
772-
if (interval >= 16) {
773-
sequence$$1 = new Sequence(interval);
774-
} else {
775-
throw new RangeError('Sequence interval must be at least 16ms.')
776-
}
758+
if (options.interval) {
759+
sequence$$1 = new Sequence(options.interval);
777760
}
778761

779762
var nodes = $(target);
@@ -879,8 +862,8 @@ function reveal(target, options, interval, sync) {
879862
* If reveal wasn't invoked by sync, we want to
880863
* make sure to add this call to the history.
881864
*/
882-
if (!sync) {
883-
this.store.history.push({ target: target, options: options, interval: interval });
865+
if (syncing !== true) {
866+
this.store.history.push({ target: target, options: options });
884867

885868
/**
886869
* Push initialization to the event queue, giving
@@ -916,7 +899,7 @@ function sync() {
916899
var this$1 = this;
917900

918901
each(this.store.history, function (record) {
919-
reveal.call(this$1, record.target, record.options, record.interval, true);
902+
reveal.call(this$1, record.target, record.options, true);
920903
});
921904

922905
initialize.call(this);
@@ -1060,7 +1043,7 @@ function transitionSupported() {
10601043
return 'transition' in style || 'WebkitTransition' in style
10611044
}
10621045

1063-
var version = "4.0.0-beta.26";
1046+
var version = "4.0.0-beta.27";
10641047

10651048
var _config;
10661049
var _debug;

0 commit comments

Comments
 (0)