Created
November 9, 2012 01:49
-
-
Save mpezzi/4043211 to your computer and use it in GitHub Desktop.
jQuery Cycle w/ Fragment Support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* jQuery Cycle w/ Fragment Support by M. Pezzi | |
* Dual licensed under the MIT and GPL licences: | |
* http://www.opensource.org/licenses/mit-license.php | |
* http://www.gnu.org/licenses/gpl.html | |
* Requires: jQuery v1.4 or later | |
*/ | |
$(function(){ | |
var $cycle = $('#cycle .cycle-inner') | |
, $cycle_prev = $('a.cycle-prev') | |
, $cycle_next = $('a.cycle-next') | |
, startingSlide = $.param.fragment() ? $('#' + $.param.fragment()).prevAll().length : 0; | |
$cycle | |
.cycle({ | |
width: 960, | |
height: 400, | |
timeout: 0, | |
startingSlide: startingSlide, | |
before: function(curr, next, opts) { | |
// Before transition. | |
}, | |
after: function(curr, next, opts) { | |
var curr_id = $('div.slide:eq(' + opts.currSlide + ')').attr('id') | |
, prev_id = $('div.slide:eq(' + ( opts.currSlide - 1 ) + ')').attr('id') | |
, next_id = $('div.slide:eq(' + ( opts.currSlide + 1 ) + ')').attr('id'); | |
// Update Prev/Next buttons. | |
$cycle_prev[opts.currSlide == 0 ? 'hide' : 'show']().attr('href', '#' + prev_id); | |
$cycle_next[opts.currSlide == opts.slideCount - 1 ? 'hide' : 'show']().attr('href', '#' + next_id); | |
} | |
}); | |
$(window).bind('hashchange', function(e){ | |
$cycle.cycle( $('#' + e.fragment).prevAll().length ); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment