Browse Source

Next version

pull/21/head
Viljami S 13 years ago
parent
commit
c279d41a91
  1. 58
      example/index.html
  2. 145
      example/styles.css
  3. 203
      responsiveslides.js

58
example/index.html

@ -4,24 +4,34 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>ResponsiveSlides.js &middot; Responsive jQuery Slideshow</title> <title>ResponsiveSlides.js &middot; Responsive jQuery Slideshow</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<link rel="stylesheet" href="styles.css?v1.03" /> <link rel="stylesheet" href="styles.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="../responsiveslides.min.js"></script> <script src="../responsiveslides.js"></script>
<script> <script>
jQuery(function() { jQuery(function() {
// Slideshow 1 // Slideshow 1
$("#slides").responsiveSlides({ $("#slides1").responsiveSlides({
maxwidth: 800 maxwidth: 800
}); });
// Slideshow 2 // Slideshow 2
$("#slides2").responsiveSlides({ $("#slides2").responsiveSlides({
fade: 300, maxwidth: 800
});
// Slideshow 3
$("#slides3").responsiveSlides({
auto: false, auto: false,
fade: 300,
maxwidth: 540 maxwidth: 540
}); });
// Slideshow 4
$("#slides4").responsiveSlides({
auto: false,
fade: 300,
maxwidth: 540
});
}); });
</script> </script>
</head> </head>
@ -31,18 +41,36 @@
<h2>Responsive jQuery Slideshow plugin that weights under 1kb</h2> <h2>Responsive jQuery Slideshow plugin that weights under 1kb</h2>
<!-- Slideshow 1 --> <!-- Slideshow 1 -->
<div id="slides"> <ul id="slides1" class="slides">
<img src="1.jpg" alt="" /> <li><img src="1.jpg" alt="" /></li>
<img src="2.jpg" alt="" /> <li><img src="2.jpg" alt="" /></li>
<img src="3.jpg" alt="" /> <li><img src="3.jpg" alt="" /></li>
</div> </ul>
<!-- Slideshow 2 --> <!-- Slideshow 2 -->
<div id="slides2"> <ul id="slides2" class="slides">
<img src="1.jpg" alt="" /> <li><a href=""><img src="1.jpg" alt="" /></a></li>
<img src="2.jpg" alt="" /> <li><a href=""><img src="2.jpg" alt="" /></a></li>
<img src="3.jpg" alt="" /> <li><a href=""><img src="3.jpg" alt="" /></a></li>
</div> </ul>
<!-- Slideshow 3 -->
<ul id="slides3" class="slides pagination">
<li><img src="1.jpg" alt="" /></li>
<li><img src="2.jpg" alt="" /></li>
<li><img src="3.jpg" alt="" /></li>
</ul>
<!-- Slideshow 4 -->
<ul id="slides4" class="slides pagination">
<li><a href=""><img src="1.jpg" alt="" /></a></li>
<li><a href=""><img src="2.jpg" alt="" /></a></li>
<li><a href=""><img src="3.jpg" alt="" /></a></li>
</ul>
<p class="test">
mopmop
</p>
<a href="http://responsive-slides.viljamis.com/" id="download">See the documentation</a> <a href="http://responsive-slides.viljamis.com/" id="download">See the documentation</a>
<p class="footer">ResponsiveSlides.js is created by <a href="http://viljamis.com">@viljamis</a>. It's released under the MIT license. If you have any questions or feedback you can use the <a href="https://github.com/viljami/ResponsiveSlides.js">GitHub project page</a>.</p> <p class="footer">ResponsiveSlides.js is created by <a href="http://viljamis.com">@viljamis</a>. It's released under the MIT license. If you have any questions or feedback you can use the <a href="https://github.com/viljami/ResponsiveSlides.js">GitHub project page</a>.</p>

145
example/styles.css

@ -8,40 +8,69 @@ html {
} }
body { body {
-webkit-font-smoothing: antialiased;
font: 14px/20px Helvetica, Arial, sans-serif;
text-shadow: 0 -2px 1px #000;
color: #888;
text-align: center;
_width: 70%; _width: 70%;
max-width: 800px; color: #888;
font: 14px/20px Helvetica, Arial, sans-serif;
margin: 20px auto 0; margin: 20px auto 0;
max-width: 800px;
text-align: center;
text-shadow: 0 -2px 1px #000;
-webkit-font-smoothing: antialiased;
} }
#wrapper { #wrapper {
padding: 20px; padding: 20px;
} }
.rslides1 { .slides {
-webkit-box-shadow: 0 0 20px #000;
-moz-box-shadow: 0 0 20px #000;
box-shadow: 0 0 20px #000; box-shadow: 0 0 20px #000;
margin-bottom: 40px; -moz-box-shadow: 0 0 20px #000;
-webkit-box-shadow: 0 0 20px #000;
margin: 0 auto 40px !important;
} }
.rslides2 {
margin: 0 auto;
/* moved these from js file to here */
.slides {
overflow: hidden;
position: relative;
width: 100%;
list-style: none;
padding: 0;
margin: 0;
}
.slides li {
height: inherit;
left: 0;
position: absolute;
top: 0;
width: 100%;
}
.slides img {
display: block;
width: 100%;
height: auto;
}
/* moving ends */
.pagination {
margin-bottom: 0 !important;
} }
p { p {
text-align: left;
max-width: 500px;
margin: 0 auto 20px; margin: 0 auto 20px;
max-width: 500px;
text-align: left;
} }
h1 { h1 {
font: 36px/50px "Helvetica Neue", Helvetica, Arial, sans-serif;
color: #fff; color: #fff;
font: 36px/50px "Helvetica Neue", Helvetica, Arial, sans-serif;
font-weight: 200; font-weight: 200;
} }
@ -51,58 +80,102 @@ h2 {
} }
a { a {
text-decoration: none;
color: #fff; color: #fff;
text-decoration: none;
}
a img {
border: none;
} }
.rslides_tabs { .rslides3_tabs {
background: rgba(0,0,0,.25);
box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
-moz-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
font-size: 18px; font-size: 18px;
margin: 0 auto 50px;
padding: 10px 0;
list-style: none; list-style: none;
width: 100%; margin: 0 auto 50px;
max-width: 540px; max-width: 540px;
padding: 10px 0;
text-align: center; text-align: center;
width: 100%;
}
.rslides3_tabs li {
display: inline;
}
.rslides3_tabs li:first-child {
margin-left: 0;
}
.rslides3_tabs a {
color: #666;
padding: 8px 20px;
-webkit-tap-highlight-color: rgba(0,0,0,.01);
}
.rslides3_tabs .rslides3_here a {
background: rgba(255,255,255,.1);
color: #fff;
font-weight: bold;
}
.rslides4_tabs {
background: rgba(0,0,0,.25); background: rgba(0,0,0,.25);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
-moz-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0); box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
-moz-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
-webkit-box-shadow: 0 0 1px rgba(255,255,255,.3), inset 0 0 5px rgba(0,0,0,1.0);
font-size: 18px;
list-style: none;
margin: 0 auto 50px;
max-width: 540px;
padding: 10px 0;
text-align: center;
width: 100%;
} }
.rslides_tabs li { .rslides4_tabs li {
display: inline; display: inline;
} }
.rslides_tabs li:first-child { .rslides4_tabs li:first-child {
margin-left: 0; margin-left: 0;
} }
.rslides_tabs a { .rslides4_tabs a {
-webkit-tap-highlight-color: rgba(0,0,0,.01);
padding: 8px 20px;
color: #666; color: #666;
padding: 8px 20px;
-webkit-tap-highlight-color: rgba(0,0,0,.01);
} }
.rslides_tabs .rslides_here a { .rslides4_tabs a:focus,
color: #fff; .rslides4_tabs a:active {
outline: none;
-webkit-tap-highlight-color: rgba(0,0,0,.01);
}
.rslides4_tabs .rslides4_here a {
background: rgba(255,255,255,.1); background: rgba(255,255,255,.1);
color: #fff;
font-weight: bold; font-weight: bold;
} }
#download { #download {
-webkit-box-shadow: 0 0 10px #000;
-moz-box-shadow: 0 0 10px #000;
box-shadow: 0 0 10px #000;
background: #333; background: #333;
background: rgba(255,255,255,.1); background: rgba(255,255,255,.1);
border: 1px solid rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.1);
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px; border-radius: 5px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
box-shadow: 0 0 10px #000;
-moz-box-shadow: 0 0 10px #000;
-webkit-box-shadow: 0 0 10px #000;
display: block;
font-size: 20px; font-size: 20px;
font-weight: bold; font-weight: bold;
margin: 60px auto; margin: 60px auto;
display: block;
max-width: 500px; max-width: 500px;
padding: 20px; padding: 20px;
} }
@ -116,9 +189,7 @@ a {
} }
@media screen and (max-width: 600px) { @media screen and (max-width: 600px) {
h1 { h1 {
font: 30px/50px "Helvetica Neue", Helvetica, Arial, sans-serif; font: 30px/50px "Helvetica Neue", Helvetica, Arial, sans-serif;
} }
} }

203
responsiveslides.js

@ -1,140 +1,157 @@
/*! ResponsiveSlides.js v1.06. (c) 2011-2012 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */ /*! ResponsiveSlides.js v1.07. (c) 2011 Viljami Salminen. MIT License. http://responsive-slides.viljamis.com */
(function($, window, i) { (function($, window, i) {
$.fn.responsiveSlides = function( options ) { $.fn.responsiveSlides = function( options ) {
// Settings
// Merge default settings with optional arguments
var settings = $.extend({ var settings = $.extend({
'speed' : 4000, "auto": true,
'fade' : 1000, "fade": 1000,
'auto' : true, "maxwidth": "none",
'maxwidth' : 'none' "speed": 4000
}, options); }, options);
return this.each( function () { return this.each( function () {
// increment i, which is used for namespacing
i++; i++;
// save handle for the slideshow
var $this = $( this ); var $this = $( this );
var slideshow = function () { var $slide = $this.children(),
var $slide = $this.find('img'), $img = $( "img", this ),
hasTouch = 'ontouchstart' in window,
startEvent = hasTouch ? 'touchstart' : 'mousedown', namespace = "rslides" + i,
namespace = 'rslides',
namespace_i = namespace + i, activeClass = namespace + "_here",
namespace_i_class = namespace + ' ' + namespace_i, slideClassPrefix = namespace + "_s",
active_class = namespace + '_here',
visible_class = namespace_i + '_on', tabsClass = namespace + "_tabs",
slide_class_prefix = namespace_i + '_s', $pagination = $( "<ul class=\"" + tabsClass + "\" />" ),
tabs_class = namespace_i + '_tabs',
fadetime = parseFloat(settings.fade), visible = {"float": "left", "position": "relative"},
$pagination = $('<ul class="' + namespace + '_tabs ' + tabs_class + '" />'), hidden = {"float": "none", "position": "absolute"},
visible = { 'position': 'relative', 'float': 'left' },
hidden = { 'position': 'absolute', 'float': 'none' }; // start index and number of slides
index = 0,
length = $slide.size();
// animations
var slideTo = function( idx ) {
$slide
.stop()
.fadeOut( settings.fade, function() {
$( this ).css( hidden );
})
.eq( idx )
.fadeIn( settings.fade, function() {
$( this ).css( visible );
index = idx;
});
};
// Only run if there's more than one slide // Only run if there's more than one slide
if ($this.find($slide).length > 1) { if ( $slide.size() > 1 ) {
// add ids to each slide
$slide.each( function ( i ) { $slide.each( function ( i ) {
this.id = slide_class_prefix + i; this.id = slideClassPrefix + i;
}); });
$slide.css({ // add css to the slideshow
'top': 0, $this.css({
'left': 0, "max-width": settings.maxwidth
'width': '100%',
'height': 'inherit',
'position': 'absolute'
}); });
$this.css({ // hide all slides, then show first one
'max-width': parseFloat(settings.maxwidth), $slide
'width': '100%', .hide()
'overflow': 'hidden', .eq( 0 )
'position': 'relative' .css( visible )
}) .show();
.addClass(namespace_i_class)
.find(':first-child').css(visible).end()
.find($slide + ':gt(0)').hide();
// Auto: true // Auto: true
if ( settings.auto === true ) { if ( settings.auto === true ) {
// rotate slides automatically
setInterval( function () { setInterval( function () {
$this.find(':first-child').fadeOut(fadetime, function () { var idx = index + 1 < length ? index + 1 : 0;
$(this).css(hidden); slideTo( idx );
}).next($slide).fadeIn(fadetime, function () { }, settings.speed );
$(this).css(visible);
}).end().appendTo($this);
}, parseFloat(settings.speed));
}
// Auto: false // Auto: false
} else { else {
var t = '';
// build pagination
var tabMarkup = [];
$slide.each( function( i ) { $slide.each( function( i ) {
var n = i + 1; var n = i + 1;
t +=
'<li>' +
'<a href="#" class="' + slide_class_prefix + n + '">' + n + '</a>' +
'</li>';
});
$pagination.append(t);
$this.after($pagination).find(':first-child').addClass(visible_class);
$('.' + slide_class_prefix + '1').parent().addClass(active_class);
$('.' + tabs_class + ' a').each(function (i) { tabMarkup.push( "<li>" );
tabMarkup.push( "<a href=\"#" + slideClassPrefix + n + "\" " );
tabMarkup.push( "class=\"" + slideClassPrefix + n + "\">" + n + "</a>" );
tabMarkup.push( "</li>" );
});
$pagination.append( tabMarkup.join("") );
var $el = $(this); var $tabs = $pagination.find( "a" );
$el.bind('click', function (e) { // add click/touch event handler and set first tab active
$tabs.on( "ontouchstart" in window ? "touchstart" : "click", function( e ) {
e.preventDefault(); e.preventDefault();
});
$el.bind(startEvent, function () { // get index of clicked tab
var idx = $tabs.index( this );
// Prevent clicking if animated // break here if element is already active
if ($('.' + visible_class + ':animated').length) { if( index === idx ) {
return false; return;
} }
if (!($el.parent().hasClass(active_class))) { // remove active state from old tab and set new one
$('.' + tabs_class + ' li').removeClass(active_class); $tabs
$('.' + visible_class).stop().fadeOut(fadetime, function () { .closest( "li" )
$(this).removeClass(visible_class).css(hidden); .removeClass( activeClass )
}).end(); .eq( idx )
$('#' + slide_class_prefix + i).stop().fadeIn(fadetime, function () { .addClass( activeClass );
$(this).addClass(visible_class).css(visible);
}).end(); // do the animation
$el.parent().addClass(active_class); slideTo( idx );
})
.eq( 0 )
.closest( "li" )
.addClass( activeClass );
// inject pagination
$this.after( $pagination );
} }
});
});
} }
}
}; // only add fallback if maxwidth isn't supported and maxwidth is set
if ( typeof document.body.style.maxWidth === "undefined" && options && options.maxwidth ) {
// Fallback to make IE6 support CSS max-width // Fallback to make IE6 support CSS max-width
var widthSupport = function() { var widthSupport = function() {
var maxwidth = parseFloat(settings.maxwidth);
if (options && options.maxwidth) { $this.css( "width", "100%" );
if (typeof document.body.style.maxHeight === 'undefined') {
$this.each(function () { if ( $this.width() > settings.maxwidth ) {
$this.css('width', '100%'); $this.css( "width", settings.maxwidth );
if ($this.width() > maxwidth) {
$this.css('width', maxwidth);
} else if ($this.width() < maxwidth) {
$this.css('width', '100%');
}
});
}
} }
}; };
// Call once
slideshow();
widthSupport(); widthSupport();
// Call on resize // bind on window resize
$(window).resize(function () { $( window ).on( "resize", function () {
widthSupport(); widthSupport();
}); });
}
}); });
}; };
})(jQuery, this, 0); })(jQuery, this, 0);
Loading…
Cancel
Save