Skip to content
This repository was archived by the owner on Aug 31, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/responsive-carousel.drag.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@
dragThreshold = function( deltaX ){
return Math.abs( deltaX ) > 4;
},
isLooped = function( $element ) {
return $element.attr( "data-loop" ) !== "false";
},
getActiveSlides = function( $carousel, deltaX ){
var $from = $carousel.find( "." + pluginName + "-active" ),
activeNum = $from.prevAll().length + 1,
forward = deltaX < 0,
nextNum = activeNum + (forward ? 1 : -1),
$to = $carousel.find( "." + itemClass ).eq( nextNum - 1 );

if( !$to.length ){
if( !$to.length && isLooped( $carousel ) ){
$to = $carousel.find( "." + itemClass )[ forward ? "first" : "last" ]();
}

Expand All @@ -38,6 +41,10 @@

var activeSlides = getActiveSlides( $( e.target ), data.deltaX );

if( !!activeSlides[ 1 ] && !activeSlides[ 1 ].length ){
return;
}

activeSlides[ 0 ].css( "left", data.deltaX + "px" );
activeSlides[ 1 ].css( "left", data.deltaX < 0 ? data.w + data.deltaX + "px" : -data.w + data.deltaX + "px" );
} )
Expand All @@ -48,6 +55,10 @@
var activeSlides = getActiveSlides( $( e.target ), data.deltaX ),
newSlide = Math.abs( data.deltaX ) > 45;

if( !!activeSlides[ 1 ] && !activeSlides[ 1 ].length ){
return;
}

$( e.target ).one( navigator.userAgent.indexOf( "AppleWebKit" ) ? "webkitTransitionEnd" : "transitionEnd", function(){
activeSlides[ 0 ].add( activeSlides[ 1 ] ).css( "left", "" );
$( e.target ).trigger( "goto." + pluginName, activeSlides[ newSlide ? 1 : 0 ] );
Expand Down
1 change: 1 addition & 0 deletions test/functional/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ <h1>Responsive Carousel variations</h1>
<ul>
<li><a href="default.html">Default, no transitions</a>
<li><a href="no-loop.html">Default, no revolving content</a>
<li><a href="no-loop-touch.html">Touch/Drag, no revolving content</a>
<li><a href="fade.html">Fade transitions</a></li>
<li><a href="fade-auto.html">Fade with autoplay</a></li>
<li><a href="slide.html">Slide transition with touch</a></li>
Expand Down
41 changes: 41 additions & 0 deletions test/functional/no-loop-touch.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Responsive Carousel Demo Page</title>
<!-- Load local jQuery, removing access to $ (use jQuery, not $). -->
<script src="../../libs/jquery/jquery.js"></script>
<link rel="stylesheet" href="../../src/responsive-carousel.css" media="screen">
<link rel="stylesheet" href="../assets/demostyles.css">
<!-- Load local lib and tests. -->
<script src="../../src/responsive-carousel.js"></script>
<script src="../../src/responsive-carousel.touch.js"></script>
<script src="../../src/responsive-carousel.drag.js"></script>
<script src="../../src/responsive-carousel.loop.js"></script>
<script src="../../src/responsive-carousel.autoinit.js"></script>
<style>
a.next, a.prev {
opacity: 0.9;
}

a.next.disabled, a.prev.disabled {
opacity: 0.3;
pointer-events: none;
}
</style>
</head>
<body>
<div class="carousel" data-loop="false">
<div>
<img src="../assets/large.jpg">
</div>
<div>
<img src="../assets/monks.jpg">
</div>
<div>
<img src="../assets/monkey.jpg">
</div>
</div>
</body>
</html>