Last active
December 22, 2015 16:39
-
-
Save jeffturcotte/6501188 to your computer and use it in GitHub Desktop.
Cycle 2 BG lookahead plugin
This file contains hidden or 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
/*! Cycle2 lookahead plugin for backgrounds | |
* Copyright (c) 2013 M. Alsup; Dual licensed: MIT/GPL | |
* @author Jeff Turcotte <[email protected]> | |
*/ | |
(function($) { | |
"use strict"; | |
$(document).on( 'cycle-initialized', function(e, opts) { | |
var key = 'cycle-look-ahead'; | |
opts.container.on( 'cycle-before', function( e, opts, outgoing, incoming, fwd ) { | |
var index = fwd ? (opts.nextSlide + 1) : (opts.nextSlide - 1), | |
slide = $( opts.slides[ index ] ), | |
images; | |
if ( slide.length && ! slide.data( key ) ) { | |
slide.data( key, true ); | |
backgrounds = slide.find('[data-cycle-bg]'); | |
if (slide.is('[data-cycle-bg]')) { | |
backgrounds.add(slide); | |
} | |
backgrounds.each(function() { | |
var elem = $(this); | |
elem.css('background-image', elem.attr('data-cycle-bg')); | |
elem.removeAttr( 'data-cycle-bg' ); | |
}); | |
} | |
}); | |
}); | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment