Skip to content

Instantly share code, notes, and snippets.

@bzalasky
Last active December 14, 2015 15:18
Show Gist options
  • Select an option

  • Save bzalasky/5106505 to your computer and use it in GitHub Desktop.

Select an option

Save bzalasky/5106505 to your computer and use it in GitHub Desktop.
This is a simple jQuery carousel plugin. In this context, I'm using it to illustrate how to write a jQuery plugin.
// new $.carousel([el], [options])
var carousel = new $.carousel('#carousel ul', {height: 438, width: 700});
<section id="carousel">
<ul>
<li>
<img src="img/one.jpg" alt="First Image" />
</li>
<li>
<img src="img/two.jpg" alt="Second Image" />
</li>
<li>
<img src="img/three.jpg" alt="3rd Image" />
</li>
</ul>
<nav>
<a class="next" href="#" title="Next Slide"></a>
<a class="prev" href="#" title="Previous Slide"></a>
</nav>
</section>
/* ==========================================================================
Carousel.js styles
========================================================================== */
#carousel {position:relative;}
#carousel ul {position:relative;height:438px;width:700px;list-style:none;margin:0;padding:0;}
#carousel li {position:absolute;top:0;left:0;}
#carousel li img {width:100%;}
/*
* Fancy CSS arrows via css-tricks.com
*/
#carousel nav a {position:absolute;height:0;width:0;top:50%;margin-top:-22px;border-top:22px solid transparent;border-bottom:22px solid transparent;}
#carousel nav a.next {right:5px;border-left-color:#efefef;border-left:22px solid rgba(255,255,255,0.4);}
#carousel nav a.prev {left:5px;border-right-color:#efefef;border-right:22px solid rgba(255,255,255,0.4);}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment