Skip to content

Instantly share code, notes, and snippets.

@sebastien-p
Created June 11, 2012 08:43
Show Gist options
  • Save sebastien-p/2909119 to your computer and use it in GitHub Desktop.
Save sebastien-p/2909119 to your computer and use it in GitHub Desktop.
Infinite carousel using YMslider 1.0.8 (http://code.google.com/p/ymslider - http://jsfiddle.net/mSvHD/20/)
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Infinite carousel using YMslider 1.0.8</title>
<link rel="stylesheet" href="jQuery.YMslider.core-min.css">
<link rel="stylesheet" href="jQuery.YMslider.default-min.css">
<link rel="stylesheet" href="jQuery.YMslider.infinite.css">
</head>
<body>
<ul class="infinite">
<li>Panel 1</li>
<li>Panel 2</li>
<li>Panel 3</li>
<li>Panel 4</li>
<li>Panel 5</li>
</ul>​
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="jQuery.YMslider-min.js?v=1.0.8"></script>
<script src="main.js"></script>
</body>
</html>
.YMslider > .infinite {
overflow: visible; position: relative; zoom: 1
}
.YMslider > .infinite:before, .YMslider > .infinite:after {
content: ""; display: table
}
.YMslider > .infinite:after { clear: both }
MIT License (http://www.opensource.org/licenses/mit-license.php) :
Copyright (c) 2012 Sebastien P. (http://twitter.com/_sebastienp)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
$(".infinite").YMslider({ stop: function () {
var $list = this.children(".panels"),
$items = $list.children(),
$first = $items.eq(0),
$last = $items.eq(-1),
width = this.width();
// if we're currently viewing the last panel (get the 'margin-left' css
// value (string) excluding "-" and "px", i.e. "600" == (3 - 1) * 300)
$list.css("margin-left").slice(1, -2) == ($items.length - 1) * width ?
// reset the 'margin-left' css value
$list.css("margin-left", width) &&
// get the last panel, apply some styles to it
// and instert it right before the first one
$first.before($last.css({ left: -width, position: "absolute" }))
// if we're starting a new cycle, reset everything back to normal
: $first.hasClass("last") && $last.after($first.css("position", "static"))
} });​
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment