jquery实现自动切换背景

<?xml version="1.0"?>
 
		<form action="#"><div>
			<div class="column">
				<div class="row">
					<select id="effect">
						<option value="none">None</option>
						<option value="fade">Fade</option>
						<option value="simpleSlide">Simple Slider</option>
						<option value="superSlide">Super Slider</option>
					</select>
				</div>
				<div class="row slide-directions">
					
					<div class="column small">
						<div class="row"><input type="radio" id="dir-n" name="direction" class="direction" checked="checked"/><label for="dir-n">North</label></div>
						<div class="row"><input type="radio" id="dir-s" name="direction" class="direction"/><label for="dir-s">South</label></div>
						<div class="row"><input type="radio" id="dir-w" name="direction" class="direction"/><label for="dir-w">West</label></div>
						<div class="row"><input type="radio" id="dir-e" name="direction" class="direction"/><label for="dir-e">East</label></div>
					</div>
					<div class="column small super-directions">
						<div class="row"><input type="radio" id="dir-nw" name="direction" class="direction"/><label for="dir-nw">North-West</label></div>
						<div class="row"><input type="radio" id="dir-ne" name="direction" class="direction"/><label for="dir-ne">North-East</label></div>
						<div class="row"><input type="radio" id="dir-sw" name="direction" class="direction"/><label for="dir-sw">South-West</label></div>
						<div class="row"><input type="radio" id="dir-se" name="direction" class="direction"/><label for="dir-se">South-East</label></div>
					</div>
				</div>
				<div class="row">
					<h2>Sequence Mode</h2>
					<input type="radio" id="normal" name="mode" class="mode" checked="checked"/><label for="normal">Normal</label>
					<input type="radio" id="back" name="mode" class="mode"/><label for="back">Back</label>
					<span class="mode-randome"><input type="radio" id="random" name="mode" class="mode"/><label for="random">Random</label></span>
				</div>
			</div>
			<div class="column">
				<div class="row">
					<h2>Manual Controls</h2>
					<div class="nav-buttons">
						<a href="javascript:;" id="prev">Previouse image</a>&nbsp;&nbsp;&nbsp;
						<a href="javascript:;" id="next">Next image</a>
					</div>
				</div>
				<div class="row nav-buttons">
					<span class="pager">Pager:</span> <div id="nav">&nbsp;</div>
				</div>
				<div class="row">
					<a href="javascript:;" id="toggleAnimation" >Pause Animation</a>
				</div>
			</div>
		</div></form>
	</div></div>	
	<div class="page-bottom">&nbsp;</div>
</div>
<div style="text-align:center;clear:both">
</div>

main.js
var slide_effect = ‘fade’;
var slide_direction = ‘N’;
var slide_mode = ‘normal’;

$(document).ready(function(){

bindEvents();

});

function bindEvents(){

// set options 
if (slide_effect == 'fade' || slide_effect == 'none') {
	hideObject($('.slide-directions'), 'slide')
} else {
	if (slide_effect == 'simpleSlide') {
		hideObject($('.mode-randome'), 'none');
		if (slide_mode == 'random') slide_mode = 'normal';	
		if ($('INPUT.direction').index($("INPUT#dir-"+slide_direction.toLowerCase()+"")) > 3) {
			slide_direction = 'N';
		}
		
	} else showObject($('.mode-randome'), 'none'); 

	showObject($('.slide-directions'), 'slide');
	
	if (slide_effect == 'superSlide') showObject($('.super-directions'), 'none'); 
		else hideObject($('.super-directions'), 'none');
}
	
if (slide_mode == 'random') {	
	$('#nav').html('');
	hideObject($('.nav-buttons'), 'fade');
} else showObject($('.nav-buttons'), 'fade');
	
$('#toggleAnimation').html("Pause Animation");

$("select#effect option[value='"+slide_effect+"']").attr("selected", true);
$("INPUT#dir-"+slide_direction.toLowerCase()+"").attr('checked', 'checked');
$("INPUT#"+slide_mode+"").attr('checked', 'checked');

// Play / pause button
$('#toggleAnimation').unbind('click');
$('#toggleAnimation').click(function(){
	if ($(this).html() == "Pause Animation"){
		$(this).html("Resume Animation");
		$('BODY').bgStretcher.pause();
	} else {
		$(this).html("Pause Animation");
		$('BODY').bgStretcher.play();
	}
});

// Change Effect
$('SELECT#effect').unbind('change');
$('SELECT#effect').change(function(){
	if ($(this).val() == slide_effect) return true;
	slide_effect = $(this).val();
	$('BODY').bgStretcher.sliderDestroy();
	initBgStretcher();
	bindEvents();
	return true;
});

// Change Direction
$('INPUT.direction').unbind('change');
$('INPUT.direction').change(function(){	
	var new_slide_deriction = $('INPUT.direction:checked').attr('id').split('dir-');
	new_slide_deriction = new_slide_deriction[1].toUpperCase();

	if (new_slide_deriction == slide_direction)	return true;
	slide_direction = new_slide_deriction;

	$('BODY').bgStretcher.sliderDestroy();
	initBgStretcher();
	bindEvents();
	return true;
});

// Change Mode
$('INPUT.mode').unbind('change');
$('INPUT.mode').change(function(){	
	if ($(this).attr('id') == slide_mode) return true;
	slide_mode = $(this).attr('id');

	$('BODY').bgStretcher.sliderDestroy();
	initBgStretcher();
	bindEvents();
	return true;
});

return true;

}

function initBgStretcher(){

$('BODY').bgStretcher({
	images: ['images/sample-1.jpg', 'images/sample-2.jpg', 'images/sample-3.jpg', 'images/sample-4.jpg', 'images/sample-5.jpg', 'images/sample-6.jpg'],
	imageWidth: 1024, 
	imageHeight: 768, 
	slideDirection: slide_direction,
	slideShowSpeed: 1000,
	transitionEffect: slide_effect,
	sequenceMode: slide_mode,
	buttonPrev: '#prev',
	buttonNext: '#next',
	pagination: '#nav',
	anchoring: 'left center',
	anchoringImg: 'left center'
});

}

function hideObject(obj, hide_effect) {
if ((KaTeX parse error: Expected 'EOF', got '&' at position 16: .browser.msie) &̲& (parseInt(jQu….browser.msie) && (parseInt(jQuery.browser.version) == 6)) {
obj.css({position: ‘static’, left: ‘0px’});
} else {
if (hide_effect == ‘slider’) obj.slideDown();
else if (hide_effect == ‘fade’) obj.fadeIn();
else obj.show();
}
return true;
}
main.css
/*
Background Stretcher jQuery Plugin
?2009 ajaxBlender.com
*/
HTML, BODY {
margin:0px;
padding:0px;
}
BODY {
font-family: “Lucida Grande”, Arial, Helvetica, sans-serif;
color: #666666;
font-size: 12px;
background: #000;
height:100%;
text-align: center;
}
A { color: #0A8ECC; }
A:HOVER {
text-decoration: none;
color: #CCC;
}
H1, H2 {
color: #CCC;
margin: 0;
padding: 0 0 5px 0;
font-size: 16px;
padding-bottom: 3px;
margin-bottom: 15px;
border-bottom: 1px solid #ccc;
}
H1 {
padding-bottom: 3px;
margin-bottom: 15px;
border-bottom: 1px solid #ccc;
}
H2 { font-size: 14px;}
.bgstretcher-page { text-align: center;}
#page {
margin: 0 auto;
width: 800px;
text-align: left;
}
.page-top, .page-bottom,
.page-content {
float: left;
width: 100%;
}
.page-top, .page-bottom { height: 30px;}
.page-top {
margin-top: 30px;
background: url(“images/bg/page-top.png”) no-repeat left top;
_background: none;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’./images/bg/page-top.png’, sizingMethod=‘image’);
}
.page-bottom {
background: url(“images/bg/page-bottom.png”) no-repeat left top;
_background: none;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’./images/bg/page-bottom.png’, sizingMethod=‘image’);
}
.page-content {
font-size: 12px;
color: #ccc;
background: url(“images/bg/page-bg.png”) repeat-y left top;
_background: none;
_filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=’./images/bg/page-bg.png’, sizingMethod=‘scale’);
}
.page-wrapper {
float: left;
width: 740px;
display: inline;
margin-left: 30px;
}
.column {
float: left;
width: 320px;
margin-right: 40px;
}
.column .row {
float: left;
width: 100%;
padding-bottom: 13px;
}
.column.small { width: 90px; }
.column.small .row { padding-bottom: 5px;}
.column SELECT { width: 180px;}
.column LABEL {cursor: pointer;}
.column .row SPAN.pager { float: left; margin-right: 15px;}
.column .row A { position: relative; }
P.larger-size { font-size: 16px; }
#page STRONG { color: #FFFFFF; }
#nav UL {
list-style: none;
margin: 0;
padding: 0;
}
#nav UL LI {
display: inline;
margin-right: 8px;
}
#nav UL LI.showPage A { color: #fff; }

bgstretcher.css
/*
Background Stretcher jQuery Plugin
?2011 ajaxBlender.com
For any questions please visit www.ajaxblender.com
or email us at support@ajaxblender.com
*/

HTML {_background: url(/images/trans.gif) no-repeat fixed;}
.bgstretcher-area { text-align: left; }
.bgstretcher, .bgstretcher UL, .bgstretcher UL LI {
position: absolute;
top: 0;
left: 0;
}
.bgstretcher UL, .bgstretcher UL LI {
margin: 0;
padding: 0;
list-style: none;
}
.bgstretcher {
background: black;
overflow: hidden;
width: 100%;
position: fixed;
z-index: 1;
_position: absolute; /IE6 doesn’t support fixed positioning/
top: 0;
left: 0;
}
bgstretcher.js
/*
Background Stretcher jQuery Plugin
?2011 ajaxBlender.com
For any questions please visit www.ajaxblender.com
or email us at support@ajaxblender.com

Version: 2.0.1

*/

;(function($){
/* Variables */
var container = null;
var allLIs = ‘’, containerStr = ‘’;

var element = this;
var _bgStretcherPause = false;
var _bgStretcherAction = false;
var _bgStretcherTm = null;
var random_line = new Array();
var random_temp = new Array();
var r_image = 0;
var swf_mode = false;
var img_options = new Array();

$.fn.bgStretcher = function(settings){
	
	if ($('.bgstretcher-page').length || $('.bgstretcher-area').length) {
		if(typeof(console) !== 'undefined' && console != null) console.log('More than one bgStretcher'); 
		return false;
	}
	settings = $.extend({}, $.fn.bgStretcher.defaults, settings);
	$.fn.bgStretcher.settings = settings;
	
	function _build(body_content){
		if(!settings.images.length){ return; }
		
		_genHtml(body_content);

		containerStr = '#' + settings.imageContainer;
		container = $(containerStr);
		allLIs = '#' + settings.imageContainer + ' LI';
		$(allLIs).hide().css({'z-index': 1, overflow: 'hidden'});
		
		if(!container.length){ return; }
		$(window).resize(function(){
			_resize(body_content)
		});
		
		_resize(body_content);
		
		var stratElement = 0;
		/*  Rebuild images for simpleSlide  */
		if (settings.transitionEffect == 'simpleSlide') {
			if (settings.sequenceMode == 'random') {
				if(typeof(console) !== 'undefined' && console != null) {
					console.log('Effect \'simpleSlide\' don\'t be to use with mode random.');
					console.log('Mode was automaticly set in normal.');
				}
			}
			$(allLIs).css({'float': 'left', position: 'static'});
			$(allLIs).show();
			if ($.fn.bgStretcher.settings.slideDirection == 'NW' || $.fn.bgStretcher.settings.slideDirection == 'NE') {
				$.fn.bgStretcher.settings.slideDirection = 'N';
			}
			if ($.fn.bgStretcher.settings.slideDirection == 'SW' || $.fn.bgStretcher.settings.slideDirection == 'SE') {
				$.fn.bgStretcher.settings.slideDirection = 'S';
			}
			if ($.fn.bgStretcher.settings.slideDirection == 'S' || $.fn.bgStretcher.settings.slideDirection == 'E') {
				settings.sequenceMode = 'back';
				$(allLIs).removeClass('bgs-current');
				$(allLIs).eq($(allLIs).length - $.fn.bgStretcher.settings.startElementIndex - 1).addClass('bgs-current');
				if ($.fn.bgStretcher.settings.slideDirection == 'E') {
					l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
					t = 0;
				} else { // S
					t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
					l = 0;
				}
				$(containerStr+' UL').css({left: l+'px', top: t+'px'});
			} else {
				settings.sequenceMode = 'normal';
				if ($.fn.bgStretcher.settings.startElementIndex != 0) {
					if ($.fn.bgStretcher.settings.slideDirection == 'N') {
						t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
						l = 0;
					} else { // W
						l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
						t = 0;
						console.log(l);
					}
					$(containerStr+' UL').css({left: l+'px', top: t+'px'});
				}
			}
		}
		
		if ($(settings.buttonNext).length || $(settings.buttonPrev).length || $(settings.pagination).length){
			if (settings.sequenceMode == 'random') {
				if(typeof(console) !== 'undefined' && console != null) {
					console.log('Don\'t use random mode width prev-button, next-button and pagination.');
				}
			} else {
				/*  Prev and Next Buttons init  */
				if ($(settings.buttonPrev).length){
					$(settings.buttonPrev).addClass('bgStretcherNav bgStretcherNavPrev');
					$(settings.buttonPrev).click(function(){
						$.fn.bgStretcher.buttonSlide('prev');
					});
				}
				if ($(settings.buttonNext).length){
					$(settings.buttonNext).addClass('bgStretcherNav bgStretcherNavNext');
					$(settings.buttonNext).click(function(){
						$.fn.bgStretcher.buttonSlide('next');
					});
				}
				/*  Pagination  */
				if ($(settings.pagination).length) {
					$.fn.bgStretcher.pagination();
				}
			}
		}
		
		/*  Random mode init  */
		if (settings.sequenceMode == 'random') {
			var i = Math.floor(Math.random()*$(allLIs).length);
			$.fn.bgStretcher.buildRandom(i);
			if (settings.transitionEffect != 'simpleSlide') {
				$.fn.bgStretcher.settings.startElementIndex = i;
			}
			stratElement = i;
		} else {
			if ($.fn.bgStretcher.settings.startElementIndex > ($(allLIs).length - 1)) $.fn.bgStretcher.settings.startElementIndex = 0;
			stratElement = $.fn.bgStretcher.settings.startElementIndex;
			if (settings.transitionEffect == 'simpleSlide') {
				if ($.fn.bgStretcher.settings.slideDirection == 'S' || $.fn.bgStretcher.settings.slideDirection == 'E') {
					stratElement = $(allLIs).length - 1 - $.fn.bgStretcher.settings.startElementIndex;
				}
			}
		}
		
		$(allLIs).eq(stratElement).show().addClass('bgs-current');
		$.fn.bgStretcher.loadImg($(allLIs).eq(stratElement));
		
		/*  Go slideshow  */
		if(settings.slideShow && $(allLIs).length > 1){
			_bgStretcherTm = setTimeout('jQuery.fn.bgStretcher.slideShow(\''+jQuery.fn.bgStretcher.settings.sequenceMode+'\', -1)', settings.nextSlideDelay);
		}
		
	};
	
	function _resize(body_content){
		var winW = 0;
		var winH = 0;
		var contH = 0;
		var contW = 0;
		
		if ($('BODY').hasClass('bgStretcher-container')) {
			winW = $(window).width();
			winH = $(window).height(); 
			if (($.browser.msie) && (parseInt(jQuery.browser.version) == 6)) {
				$(window).scroll(function(){
					$('#'+settings.imageContainer).css('top', $(window).scrollTop());
				});					
			}
		} else {
			$('.bgstretcher').css('position', 'absolute').css('top', '0px');
			winW = body_content.width();
			winH = body_content.height(); 
		}
		
		var imgW = 0, imgH = 0;
		var leftSpace = 0;
		
		//	Max image size
		if(settings.maxWidth != 'auto'){
			if (winW > settings.maxWidth){
				leftSpace = (winW - settings.maxWidth)/2;
				contW = settings.maxWidth;
			} else contW = winW;
		} else contW = winW;
		if(settings.maxHeight != 'auto'){
			if (winH > settings.maxHeight){
				contH = settings.maxHeight;
			} else contH = winH;
		} else contH = winH;
		
		//	Update container's size
		container.width(contW);
		container.height(contH);
		
		//	Non-proportional resize
		if(!settings.resizeProportionally){
			imgW = contH;
			imgH = contH;
		} else {
			var initW = settings.imageWidth, initH = settings.imageHeight;
			var ratio = initH / initW;
			
			imgW = contW;
			imgH = Math.round(contW * ratio);
			
			if(imgH < contH){
				imgH = contH;
				imgW = Math.round(imgH / ratio);
			}
		}
		
		// Anchoring
		var mar_left = 0;
		var mar_top = 0;
		var anchor_arr;
		if ($.fn.bgStretcher.settings.anchoring != 'left top') {
			anchor_arr = ($.fn.bgStretcher.settings.anchoring).split(' ');
			if (anchor_arr[0] == 'right') {
				mar_left = (winW - contW);
			} else {
				if (anchor_arr[0] == 'center') mar_left = Math.round((winW - contW)/2);
			}
			if (anchor_arr[1] == 'bottom') {
				mar_top = (winH - contH);
			} else {
				if (anchor_arr[1] == 'center') {
					mar_top = Math.round((winH - contH)/2);
				}
			}
			container.css('marginLeft', mar_left+'px').css('marginTop', mar_top+'px');
		}
		mar_left = 0;
		mar_top = 0;
		if ($.fn.bgStretcher.settings.anchoringImg != 'left top') {
			anchor_arr = ($.fn.bgStretcher.settings.anchoringImg).split(' ');
			if (anchor_arr[0] == 'right') {
				mar_left = (contW - imgW);
			} else {
				if (anchor_arr[0] == 'center') mar_left = Math.round((contW - imgW)/2);
			}
			if (anchor_arr[1] == 'bottom') {
				mar_top = (contH - imgH);
			} else {
				if (anchor_arr[1] == 'center') {
					mar_top = Math.round((contH - imgH)/2);
				}
			}
		}
		img_options['mar_left'] = mar_left;
		img_options['mar_top'] = mar_top;
		
		//	Apply new size for images
		if (container.find('LI:first').hasClass('swf-mode')) {
			
			var path_swf = container.find('LI:first').html();
			container.find('LI:first').html('<div id="bgstretcher-flash">&nbsp;</div>');
			
			var header = new SWFObject('flash/stars.swf', 'flash-obj', contW, contH, '9');
			header.addParam('wmode', 'transparent');
			header.write('bgstretcher-flash');
			
		}; 
		img_options['imgW'] = imgW;
		img_options['imgH'] = imgH;
		
		if(!settings.resizeAnimate){
			container.children('UL').children('LI.img-loaded').find('IMG').css({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'});
			container.children('UL').children('LI.img-loaded').find('IMG').css({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'});
		} else {
			container.children('UL').children('LI.img-loaded').find('IMG').animate({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'}, 'normal');
			container.children('UL').children('LI.img-loaded').find('IMG').animate({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'}, 'normal');
		}
		
		$(allLIs).width(container.width()).height(container.height());
		
		if ($.fn.bgStretcher.settings.transitionEffect == 'simpleSlide') {
			if ($.fn.bgStretcher.settings.slideDirection == 'W' || $.fn.bgStretcher.settings.slideDirection == 'E') {
				container.children('UL').width(container.width() * $(allLIs).length).height(container.height());
				if ( $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) != -1 ){
					l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * container.width()*(-1);
					container.children('UL').css({left: l+'px'});
				}
			} else {
				container.children('UL').height(container.height() * $(allLIs).length).width(container.width());
				if ( $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) != -1 ){
					t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
					container.children('UL').css({top: t+'px'});
				}
			}
		}
		
	};
	
	function _genHtml(body_content){
		var code = '';
		var cur_bgstretcher;

		body_content.each(function(){
			$(this).wrapInner('<div class="bgstretcher-page" />').wrapInner('<div class="bgstretcher-area" />');
			code = '<div id="' + settings.imageContainer + '" class="bgstretcher"><ul>';
			// if swf
			if (settings.images.length) {
				var ext = settings.images[0].split('.');
				ext = ext[ext.length-1];
				
				if (ext != 'swf') {
					var ind = 0;
					for(i = 0; i < settings.images.length; i++){
						if (settings.transitionEffect == 'simpleSlide' && settings.sequenceMode == 'back') 
							ind = settings.images.length-1-i;
								else ind = i;
						if ($.fn.bgStretcher.settings.preloadImg) {
								code += '<li><span class="image-path">' + settings.images[ind] + '</span></li>';
							} else {
								code += '<li class="img-loaded"><img src="' + settings.images[ind] + '" alt="" /></li>';
							}		
					}
				} else {
					code += '<li class="swf-mode">' + settings.images[0] + '</li>';	
				}
			}
			
			code += '</ul></div>';
			cur_bgstretcher = $(this).children('.bgstretcher-area');
			$(code).prependTo(cur_bgstretcher);
			cur_bgstretcher.css({position: 'relative'});
			cur_bgstretcher.children('.bgstretcher-page').css({'position': 'relative', 'z-index': 3});
		});

	};
	
	/*  Start bgStretcher  */
	this.addClass('bgStretcher-container');
	_build(this);
};

$.fn.bgStretcher.loadImg = function(obj){
	if (obj.hasClass('img-loaded')) return true;
	obj.find('SPAN.image-path').each(function(){
		var imgsrc = $(this).html();
		var imgalt = '';
		var parent = $(this).parent();
		var img = new Image();
		
		$(img).load(function () {
			$(this).hide();
			parent.prepend(this);
			$(this).fadeIn('100');
		}).error(function () {
		}).attr('src', imgsrc).attr('alt', imgalt);
		
		$(img).css({'marginLeft': img_options["mar_left"]+'px', 'marginTop': img_options["mar_top"]+'px'});
		$(img).css({'width': img_options["imgW"]+'px', 'height': img_options["imgH"]+'px'});
	});
	obj.addClass('img-loaded');
	return true;
}

$.fn.bgStretcher.play = function(){
   _bgStretcherPause = false;
   $.fn.bgStretcher._clearTimeout();
   $.fn.bgStretcher.slideShow($.fn.bgStretcher.settings.sequenceMode, -1);
   
};

$.fn.bgStretcher._clearTimeout = function(){
   if(_bgStretcherTm != null){
       clearTimeout(_bgStretcherTm);
       _bgStretcherTm = null;
   }
}

$.fn.bgStretcher.pause = function(){
   _bgStretcherPause = true;
   $.fn.bgStretcher._clearTimeout();
};

$.fn.bgStretcher.sliderDestroy = function(){
	var cont = $('.bgstretcher-page').html();
	$('.bgStretcher-container').html('').html(cont).removeClass('bgStretcher-container');
	$.fn.bgStretcher._clearTimeout();
	_bgStretcherPause = false;
}

/*  Slideshow  */
$.fn.bgStretcher.slideShow = function(sequence_mode, index_next){	
	_bgStretcherAction = true;
	if ($(allLIs).length < 2) return true;
	var current = $(containerStr + ' LI.bgs-current');
	var next;
    
    $(current).stop(true, true);
	
	if (index_next == -1) {
		switch (sequence_mode){
			case 'back':
				next = current.prev();
				if(!next.length){ next = $(containerStr + ' LI:last'); 	}
				break;
			case 'random':
				if (r_image == $(containerStr + ' LI').length) {
					$.fn.bgStretcher.buildRandom(random_line[$(containerStr + ' LI').length-1]);
					r_image = 0;
				}
				next = $(containerStr + ' LI').eq(random_line[r_image]);
				r_image++;
				break;
			default:
				next = current.next();
				if(!next.length){ next = $(containerStr + ' LI:first'); }	
		}
	} else {
		next = $(containerStr + ' LI').eq(index_next);
	}
	
	$(containerStr + ' LI').removeClass('bgs-current');
	$.fn.bgStretcher.loadImg(next);
	next.addClass('bgs-current');
	
	switch ($.fn.bgStretcher.settings.transitionEffect){
		case 'fade':
			$.fn.bgStretcher.effectFade(current, next);
			break;
		case 'simpleSlide':
			$.fn.bgStretcher.simpleSlide();
			break;
		case 'superSlide':
			$.fn.bgStretcher.superSlide(current, next, sequence_mode);
			break;
		default : 
			$.fn.bgStretcher.effectNone(current, next);
			
		}
	if ($($.fn.bgStretcher.settings.pagination).find('LI').length) {
		$($.fn.bgStretcher.settings.pagination).find('LI.showPage').removeClass('showPage');
		$($.fn.bgStretcher.settings.pagination).find('LI').eq($(containerStr + ' LI').index($(containerStr + ' LI.bgs-current'))).addClass('showPage');
	}
		
	// callback
	if ($.fn.bgStretcher.settings.callbackfunction) {
		if(typeof $.fn.bgStretcher.settings.callbackfunction == 'function')
				$.fn.bgStretcher.settings.callbackfunction.call();
	}	
	
	if(!_bgStretcherPause){
	  _bgStretcherTm = setTimeout('jQuery.fn.bgStretcher.slideShow(\''+jQuery.fn.bgStretcher.settings.sequenceMode+'\', -1)', jQuery.fn.bgStretcher.settings.nextSlideDelay);
	}
};

/*  Others effects  */
$.fn.bgStretcher.effectNone = function(current, next){
	next.show();
	current.hide();
	_bgStretcherAction = false;
};	
$.fn.bgStretcher.effectFade = function(current, next){
	next.fadeIn( $.fn.bgStretcher.settings.slideShowSpeed );
	current.fadeOut( $.fn.bgStretcher.settings.slideShowSpeed, function(){
		_bgStretcherAction = false;
	} );
};

$.fn.bgStretcher.simpleSlide = function(){
	var t, l;
	switch ($.fn.bgStretcher.settings.slideDirection) {
		case 'N':
		case 'S':
			t = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).height()*(-1);
			l = 0;
			break;
		default:
			l = $(containerStr + ' LI').index($(containerStr + ' LI.bgs-current')) * $(containerStr).width()*(-1);
			t = 0;
	}
	$(containerStr+' UL').animate({left: l+'px', top: t+'px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
		_bgStretcherAction = false;
	});
	
};

$.fn.bgStretcher.superSlide = function(current, next, sequence_mode){
	var t, l;
	switch ($.fn.bgStretcher.settings.slideDirection) {
		case 'S':
			t = $(containerStr).height();
			l = 0;
			break;
		case 'E':
			t = 0;
			l = $(containerStr).width();
			break;
		case 'W':
			t = 0;
			l = $(containerStr).width()*(-1);
			break;
		case 'NW':
			t = $(containerStr).height()*(-1);
			l = $(containerStr).width()*(-1);
			break;
		case 'NE':
			t = $(containerStr).height()*(-1);
			l = $(containerStr).width();
			break;
		case 'SW':
			t = $(containerStr).height();
			l = $(containerStr).width()*(-1);
			break;
		case 'SE':
			t = $(containerStr).height();
			l = $(containerStr).width();
			break;	
		default:
			t = $(containerStr).height()*(-1);
			l = 0;

	}
			
	if (sequence_mode == 'back') {
			next.css({'z-index': 2, top: t+'px', left: l+'px'});
			next.show();
			next.animate({left: '0px', top: '0px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
					current.hide();
					$(this).css({'z-index': 1});
					_bgStretcherAction = false;
				});
		} else {
				current.css('z-index', 2);
				next.show();
				current.animate({left: l+'px', top: t+'px'}, $.fn.bgStretcher.settings.slideShowSpeed, function(){
					$(this).hide().css({'z-index': 1, top: '0px', left: '0px'});
					_bgStretcherAction = false;
				});
			}	
};

/*  Build line random images  */
$.fn.bgStretcher.buildRandom = function(el_not){
	var l = $(allLIs).length;
	var i, j, rt;
	for (i = 0; i < l; i++ ) {
		random_line[i] = i;
		random_temp[i] = Math.random()*l;
	}
	for (i = 0; i < l; i++ ) {
		for (j = 0; j < (l-i-1); j++) {
			if (random_temp[j] > random_temp[j+1]) {
				rt = random_temp[j];
				random_temp[j] = random_temp[j+1];
				random_temp[j+1] = rt;
				rt = random_line[j];
				random_line[j] = random_line[j+1];
				random_line[j+1] = rt;
			}
		}
	}
	
	if (random_line[0] == el_not) {
		rt = random_line[0];
		random_line[0] = random_line[l-1];
		random_line[l-1] = rt;
	}
};

/*  Prev and Next buttons */
$.fn.bgStretcher.buttonSlide = function(button_point){
	if (_bgStretcherAction || ($(allLIs).length < 2)) return false;
	var mode = '';
	if (button_point == 'prev') {
		mode = 'back';
		if ($.fn.bgStretcher.settings.sequenceMode == 'back')  mode = 'normal';
	} else {
		mode = $.fn.bgStretcher.settings.sequenceMode;
	}
	$(allLIs).stop(true, true);
	$.fn.bgStretcher._clearTimeout();
	$.fn.bgStretcher.slideShow(mode, -1);
	return false;
};

/*  Pagination  */
$.fn.bgStretcher.pagination = function(){
	var l = $(allLIs).length;
	var output = ''; var i = 0;
	if (l > 0) {
		output += '<ul>';
			for (i = 0; i < l; i++){
				output += '<li><a href="javascript:;">'+(i+1)+'</a></li>';
			}
		output += '</ul>';
		$($.fn.bgStretcher.settings.pagination).html(output);
		$($.fn.bgStretcher.settings.pagination).find('LI:first').addClass('showPage');
		
		$($.fn.bgStretcher.settings.pagination).find('A').click(function(){
			if ($(this).parent().hasClass('showPage')) return false;
			$(allLIs).stop(true, true);
			$.fn.bgStretcher._clearTimeout();
			$.fn.bgStretcher.slideShow($.fn.bgStretcher.settings.sequenceMode, $($.fn.bgStretcher.settings.pagination).find('A').index($(this)));
			return false;
		});
		
	}
	return false;
}

/*  Default Settings  */
$.fn.bgStretcher.defaults = {
	imageContainer:             'bgstretcher',
	resizeProportionally:       true,
	resizeAnimate:              false,
	images:                     [],
	imageWidth:                 1024,
	imageHeight:                768,
	maxWidth:					'auto',
	maxHeight:					'auto',
	nextSlideDelay:             3000,
	slideShowSpeed:             'normal',
	slideShow:                  true,
	transitionEffect:			'fade', // none, fade, simpleSlide, superSlide
	slideDirection:				'N', // N, S, W, E, (if superSlide - NW, NE, SW, SE)
	sequenceMode:				'normal', // back, random
	buttonPrev:					'',
	buttonNext:					'',
	pagination: 				'',
	anchoring: 					'left top', // right bottom center
	anchoringImg: 				'left top', // right bottom center
	preloadImg:					false,
	startElementIndex:			0,
	callbackfunction:			null
};
$.fn.bgStretcher.settings = {};

})(jQuery);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值