Dissolve & Horz Scroll (ScrollMagic 1.3.0)
Horizontal Scrolling with ScrollMagicJS
by Wes Modes
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/1.3.0/jquery.scrollmagic.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ScrollMagic/1.3.0/jquery.scrollmagic.debug.js"></script>
<div id="inner-wrapper">
<div class="table-wrap" id="table-1" style="display: table-cell;">
<div class="shot-wrap shot full" id="shot-1">
<div class="content full" id="content-1">
<img src="https://doc.peoplesriverhistory.us/images/one.jpg" />
</div>
</div>
</div>
<div class="table-wrap" id="table-2" style="display: table-cell;">
<div class="shot-wrap shot full" id="shot-2">
<div class="content full" id="content-2">
<img src="https://doc.peoplesriverhistory.us/images/two.jpg" />
</div>
</div>
</div>https://jsfiddle.net/wmodes/b4gdxeLn/#mobile
<div class="table-wrap" id="table-3" style="display: table-cell;">
<div class="shot-wrap shot full" id="shot-3">
<div class="content full" id="content-3">
<img src="https://doc.peoplesriverhistory.us/images/three.jpg" />
</div>
</div>
</div>
<div class="table-wrap" id="table-4" style="display: table-cell;">
<div class="shot-wrap shot full" id="shot-4">
<div class="content full" id="content-4">
<img src="https://doc.peoplesriverhistory.us/images/four.jpg" />
</div>
</div>
</div>
</div>
CSS
body {
width: 100vw;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
padding: 0;
margin: 0;
overflow-x: scroll;
overflow-y: hidden;
font-size: 14px;
color: white;
}
#inner-wrapper {
display: table;
overflow-y: hidden;
}
.table-wrap {
display: table-cell;
}
#doc-canvas, #outer-wrapper, #inner-wrapper, #table-wrapper {
height: 100vh;
overflow: hidden;
top: 0;
position: relative;
}
.full {
height: 100vh;
width: 100vw;
overflow: hidden;
}
.shot {
width: 100vw;
float: left;
display: inline;
}
.content {
position: relative;
top: 0px;
color: white;
font-size: 14px;
}
.content img {
position: relative;
top: 0;
left: 0;
width: 100%;
vertical-align: middle;
}
#content-2 {
opacity: 1;
z-index: 10;
}
.content {
border: solid 1px red;
}
.shot {
border: dotted 1px orange;
}
.table-wrap {
border: dotted 1px yellow;
}
JavaScript
scrollControl = new ScrollMagic({
vertical: false,
});
vw = $(window).width();
console.log("width:" + vw + "px");
// pin frame 2
var myScrollScene = new ScrollScene({
triggerHook: 0,
triggerElement: '#shot-2',
// This pin is considerably longer than average
offset: 0,
// duration = stickyLength + disolve_duration
duration: 1.5 * vw + 'px'
})
.setPin('#content-2', {
pushFollowers: false
})
.addTo(scrollControl)
.addIndicators({
zindex: 100,
suffix: 'pin2'
});
// move frame 3 up early and pin it
var myScrollScene = new ScrollScene({
triggerHook: 0,
triggerElement: '#shot-2',
offset: 0,
// duartion = 1.5, but why?
duration: 1.5 * vw + 'px'
// the faux pin doesn't actually expand the container the way SM does
// so the results are a little strange
})
.on("start end", function (e) {
$('#content-3').css({left: 0, position:'fixed'});
})
.on("enter leave", function (e) {
$('#content-3').css({left: 0, position:'relative'});
})
.addTo(scrollControl)
.addIndicators({
zindex: 100,
suffix: 'pin3faux'
});
var dissolve = TweenMax.to('#content-2', 1, {
autoAlpha: 0
});
// dissolve frame 2 to frame 3
var myScrollScene = new ScrollScene({
triggerHook: 0,
// Note that though we are fading frame 2, we are
// using the arrival of frame 3 the trigger
triggerElement: '#shot-2',
// The sets the rapidity of the dissolve
// offset = stickyLength
offset: 0.33 * vw + 'px',
// The sets the rapidity of the dissolve
duration: 1 * vw + 'px'
})
.setTween(dissolve)
.addTo(scrollControl)
.addIndicators({
zindex: 100,
suffix: 'dissolve'
});
/*
// pin frame 3
var myScrollScene = new ScrollScene({
triggerHook: 0,
triggerElement: '#content-3',
// This is an ordinary pin offset/duration
offset: 0,
duration: 1 * vw + 'px'
})
.setPin('#content-3', {
...