Skip to content

Instantly share code, notes, and snippets.

@synecdocheNORTH
Created January 13, 2019 01:22
Show Gist options
  • Save synecdocheNORTH/3c0590eeeb062aa5664c32b6b47acbcd to your computer and use it in GitHub Desktop.
Save synecdocheNORTH/3c0590eeeb062aa5664c32b6b47acbcd to your computer and use it in GitHub Desktop.
Mouse driven carrousel concept
<div id="wrap">
<a href="#" class="hb">
<div class="c">
<img src="https://source.unsplash.com/user/web_tiki/2000x1300" alt=""/>
<div class="txt">
<h1>Title here</h1>
<p>Some longer text here thats wide enough to span on several lines.</p>
</div>
</div>
</a>
<div class="fullBg">
<img src="https://source.unsplash.com/user/web_tiki/2000x1300" alt=""/>
</div>
<a href="#" class="hb">
<div class="c">
<img src="https://source.unsplash.com/user/web_tiki/2000x1301" alt=""/>
<div class="txt">
<h1>Title here</h1>
<p>Some longer text here thats wide enough to span on several lines.</p>
</div>
</div>
</a>
<div class="fullBg">
<img src="https://source.unsplash.com/user/web_tiki/2000x1301" alt=""/>
</div>
<a href="#" class="hb">
<div class="c">
<img src="https://source.unsplash.com/user/web_tiki/2000x1302" alt=""/>
<div class="txt">
<h1>Title here</h1>
<p>Some longer text here thats wide enough to span on several lines.</p>
</div>
</div>
</a>
<div class="fullBg">
<img src="https://source.unsplash.com/user/web_tiki/2000x1302" alt=""/>
</div>
<a href="#" class="hb">
<div class="c">
<img src="https://source.unsplash.com/user/web_tiki/2000x1303" alt=""/>
<div class="txt">
<h1>Title here</h1>
<p>Some longer text here thats wide enough to span on several lines.</p>
</div>
</div>
</a>
<div class="fullBg">
<img src="https://source.unsplash.com/user/web_tiki/2000x1303" alt=""/>
</div>
</div>
<a href="https://unsplash.com/@web_tiki" class="credits">Photos by web-tiki<br/>on unsplash</a>

Mouse driven carrousel concept

UI test for a horizontal scroll carrousel concept. The elements scroll on mouse horizontal move.

A Pen by web-tiki on CodePen.

License.

$(document).ready(function(){
var docWidth = $('body').width(),
$wrap = $('#wrap'),
$images = $('#wrap .hb'),
slidesWidth = $wrap.width();
$(window).on('resize', function(){
docWidth = $('body').width();
slidesWidth = $wrap.width();
})
$(document).mousemove(function(e) {
var mouseX = e.pageX,
offset = mouseX / docWidth * slidesWidth - mouseX / 2;
$images.css({
'-webkit-transform': 'translate3d(' + -offset + 'px,0,0)',
'transform': 'translate3d(' + -offset + 'px,0,0)'
});
});
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
*{margin:0;padding:0;}
a {color:inherit;text-decoration:none;}
body,html{
overflow:hidden;
height:100%;
font-size:16px;
font-family: 'Montserrat', sans-serif;
background:#000;
color:#fff;
}
#wrap{
position:absolute;
left:0; top:0;
width:150%;
height:100%;
display:flex;
align-items:stretch;
margin:0 25%;
}
.hb {
position:relative;
width:25%;
z-index:1;
display:flex;
align-items:center;
z-index:2;
trasnform:scale(.97);
}
.c{
position:relative;
display:block;
max-width:90%;
}
.c img {
position:relative;
display:block;
width:100%;
height:auto;
z-index:2;
}
.txt {
position:absolute;
top:100%; left:10%;
width:80%;
opacity:0;
padding:1em 0 0 1em;
border-left:1px solid;
z-index:1;
transform:scaleY(1) translateY(-50px);
transition:transform .2s, opacity .5s;
}
h1 {
font-size:1.2em;
font-weight:700;
text-transform:uppercase;
}
.hb:hover .txt {
opacity:1;
transform:scaleY(1) translateY(0);
}
.fullBg {
position:fixed;top:0;left:0;width:100%;height:100%;
opacity:0;
transition:transform .5s, opacity .5s;
transform:scale(1);
z-index:1;
}
.fullBg img {
width:100%;height:100%;
object-fit:cover;object-position:center;
opacity:.5;
}
.hb:hover + .fullBg {opacity:1;transform:scale(1.02);}
.credits {
position:fixed;
bottom:0;right:0;
padding:1.5em;
font-size:.8em;
text-align:right;
font-style:italic;
opacity:.8;
transition:opacity .2;
z-index:3;
}
.credits:hover {
text-decoration:underline;
opacity:1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment