Slider (Transdev) DEV 0.3 with touch
by moob
HTML
<div id="aParent">
<div class="slyduh">
<ul>
<li style="background-image:url('http://lorempixel.com/400/200/')">
<h2 class="slide-in-from-left">1</h2>
<h3 class="slide-in-from-bottom">jhjhj</h3>
</li>
<li style="background-image:url('http://lorempixel.com/400/300/')">
<div id="bigger" class="slide-in-from-top">
2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2 inner 2</div>
</li>
<li style="background-image:url('http://lorempixel.com/400/400/')"><h2 class="slide-in-from-right">3</h2></li>
</ul>
</div>
<header><h1>Imagine there's an element <em>inside</em> the slider...</h1>
<p>This content that may be required to hold the slider open.</p>
</header>
</div>
<div style="margin:20px">
<h3>Responsive background slider thing</h3>
<p>Settings</p>
<code>
loop : true, //endless looping next/prev (boolean)<br />
transitionSpeed : 600, //animation speed (milliseconds)<br />
cycle : 6000, //automatically cycle through slides (pauses on hover). Delay in milliseconds (0 = no cycling)<br />
startPosition : 0, //Starting Slide Index (zero index)<br />
complete : null //function callback on complete<br />
</code>
<p><strong>Animated slide text</strong><br />
Your text can be animated when the slide comes into view. Style and position the elements as you like then apply one of the following classnames. Don't edit the '.slide-in-from-' styles.</p>
<code>
.slide-in-from-left
.slide-in-from-right
.slide-in-from-top
.slide-in-from-bottom
</code>
</div>
CSS
html, body {
margin:0;
}
header {
width:60%;
margin:auto;
border:1px dotted white;
color:#ddd;
z-index:1;
}
header:hover {
height:300px;
border-color:yellow;
}
.slyduh {
width: 100%;
min-width:100%;
max-width:100%;
max-height:100%;
overflow:hidden;
position:relative;
z-index:0;
}
.slyduh.fill {
display:block; top:0; right:0; bottom:0; left:0;
overflow:hidden;
position:absolute;
z-index:-1;
height:100%; min-height:100%;
border:0px solid red;
}
.slyduh.fill ul {
display:block; top:0; right:0; bottom:0; left:0;
position:absolute;
height:100%; min-height:100%;
}
.slyduh.fill ul li {
height:100%; min-height:100%;
}
.slyduh ul {
list-style: none;
margin: 0;
padding: 0;
position: relative;
width: 10000%;
display:block;
}
.slyduh ul > li {
display:inline-block;
position:relative;
margin-right:-4px;
width:1%;
font-size: 30px;
text-align: center;
vertical-align:top;
height:100%;
max-height:100%;
background: #666666 repeat center center;
-webkit-background-size: cover;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
color:black;
text-shadow:0px 0px 10px white;
overflow:hidden;
}
.slyduh-nextButton, .slyduh-prevButton {
display:block;
position:absolute;
height:50px;
z-index:100;
top:0;
bottom:0;
margin:auto;
right:-1px;
background:rgba(255, 255, 255, .6);
border-radius:5px 0 0 5px;
width:80px;
text-align:center;
line-height:50px;
border:1px solid white;
box-shadow:0px 0px 3px 2px rgba(0, 0, 0, .5);
}
.slyduh-prevButton {
right:auto;
left:-1px;
border-radius:0 5px 5px 0;
}
.slyduh-nextButton:hover, .slyduh-prevButton:hover {
background-color:rgba(25,255,255,.5)
}
.slyduh-dots {position:absolute; top:0; left:0; right:0; margin:auto; text-align:center; z-index:999;}
.slyduh-dots a...
JavaScript
/* touch events DEV*/
(function ($) {
var ePos = function(e){
var oe = (e.originalEvent && e.originalEvent.touches) ? e.originalEvent.touches[0] : e;
return {x:oe.pageX, y:oe.pageY};
};
$.fn.touchListener = function (options) {
var settings = $.extend({
swipeSpeedThreshold: 0.6, //drag speed in px per ms before it can be considers a swipe
swipeDistanceThreshold: 100, //distance dragged in px before it can be considers a swipe
complete: null //function callback on complete
}, options);
return this.each(function () {
var el = $(this),
touchstarted = false,
startX=0,
startY=0,
endX=0,
endY=0,
distX=0,
distY=0,
pos={x:0,y:0},
deg=-1,
dir='',
startTime = 0,
endTime = 0,
split = 0,
dur = 0,
spd = 0,
directionDistance = 0,
dist={x:0,y:0,dd:directionDistance},
touchdata = {state:'listening',
position:pos,
distance:dist,
degrees:deg,
direction:dir,
duration:dur,
speed:spd
};
el.on('touchstart, mousedown', function(e){
touchstarted=true;
pos = ePos(e);
startX = pos.x;
startY = pos.y;
startTime = new Date().getTime();
touchdata = {
state:'touchstart',
position:pos,
distance:dist,
degrees:deg,
direction:dir,
duration:dur,
...