58 230 77

特效描述:jQuery实现 带缩略图 幻灯片切换,jQuery实现带缩略图幻灯片切换代码特效


1. 引入CSS

<link rel="stylesheet" type="text/css" href="css/style.css" />

2. 引入JS

<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

3. HTML代码

		<div id="loader" class="loader"></div>
		<div class="wrapper">
			<div id="ps_container" class="ps_container">
				<div class="ps_image_wrapper">
					<!-- First initial image -->
					<img src="images/1.jpg" alt="" />
				<!-- Navigation items -->
				<div class="ps_next"></div>
				<div class="ps_prev"></div>
				<!-- Dot list with thumbnail preview -->
				<ul class="ps_nav">
					<li class="selected"><a href="images/1.jpg" rel="images/thumbs/1.jpg">Image 1</a></li>
					<li><a href="images/2.jpg" rel="images/thumbs/2.jpg">Image 2</a></li>
					<li><a href="images/3.jpg" rel="images/thumbs/3.jpg">Image 3</a></li>
					<li><a href="images/4.jpg" rel="images/thumbs/4.jpg">Image 4</a></li>
					<li><a href="images/5.jpg" rel="images/thumbs/5.jpg">Image 5</a></li>
					<li><a href="images/6.jpg" rel="images/thumbs/6.jpg">Image 6</a></li>
					<li><a href="images/7.jpg" rel="images/thumbs/7.jpg">Image 7</a></li>
					<li><a href="images/8.jpg" rel="images/thumbs/8.jpg">Image 8</a></li>
					<li><a href="images/9.jpg" rel="images/thumbs/9.jpg">Image 9</a></li>
					<li><a href="images/10.jpg" rel="images/thumbs/10.jpg">Image 10</a></li>
					<li class="ps_preview">
						<div class="ps_preview_wrapper">
							<!-- Thumbnail comes here -->
						<!-- Little triangle -->
		<!-- The JavaScript -->
        <script type="text/javascript">
			the images preload plugin
			(function($) {
				$.fn.preload = function(options) {
					var opts 	= $.extend({}, $.fn.preload.defaults, options),
						o		= $.meta ? $.extend({}, opts, this.data()) : opts;
					return this.each(function() {
						var $e	= $(this),
							t	= $e.attr('rel'),
							i	= $e.attr('href'),
							l	= 0;
							if(l==2) o.onComplete();
							if(l==2) o.onComplete();
				$.fn.preload.defaults = {
					onComplete	: function(){return false;}
        <script type="text/javascript">
			$(function() {
				//some elements..
				var $ps_container		= $('#ps_container'),
					$ps_image_wrapper 	= $ps_container.find('.ps_image_wrapper'),
					$ps_next			= $ps_container.find('.ps_next'),
					$ps_prev			= $ps_container.find('.ps_prev'),
					$ps_nav				= $ps_container.find('.ps_nav'),
					$tooltip			= $ps_container.find('.ps_preview'),
					$ps_preview_wrapper = $tooltip.find('.ps_preview_wrapper'),
					$links				= $ps_nav.children('li').not($tooltip),
					total_images		= $links.length,
					currentHovered		= -1,
					current				= 0,
					$loader				= $('#loader');
				/*check if you are using a browser*/	
				var ie 				= false;
				if ($.browser.msie) {
					ie = true;//you are not!Anyway let's give it a try
						opacity	: 0
				/*first preload images (thumbs and large images)*/
				var loaded	= 0;
					var $link 	= $(this);
						onComplete	: function(){
							if(loaded == total_images){
								//all images preloaded,
								//show ps_container and initialize events
								//when mouse enters the pages (the dots),
								//show the tooltip,
								//when mouse leaves hide the tooltip,
								//clicking on one will display the respective image	
								//navigate through the images
				function showTooltip(){
					var $link			= $(this),
						idx				= $link.index(),
						linkOuterWidth	= $link.outerWidth(),
						//this holds the left value for the next position
						//of the tooltip
						left			= parseFloat(idx * linkOuterWidth) - $tooltip.width()/2 + linkOuterWidth/2,
						//the thumb image source
						$thumb			= $link.find('a').attr('rel'),
					//if we are not hovering the current one
					if(currentHovered != idx){
						//check if we will animate left->right or right->left
						if(currentHovered != -1){
							if(currentHovered < idx){
								imageLeft	= 75;
								imageLeft	= -75;
						currentHovered = idx;
						//the next thumb image to be shown in the tooltip
						var $newImage = $('<img/>').css('left','0px')
						//if theres more than 1 image 
						//(if we would move the mouse too fast it would probably happen)
						//then remove the oldest one (:last)
						if($ps_preview_wrapper.children().length > 1)
						//prepend the new image
						var $tooltip_imgs		= $ps_preview_wrapper.children(),
							tooltip_imgs_count	= $tooltip_imgs.length;
						//if theres 2 images on the tooltip
						//animate the current one out, and the new one in
						if(tooltip_imgs_count > 1){
												//remove the old one
										 .css('left',imageLeft + 'px')
					//if we are not using a "browser", we just show the tooltip,
					//otherwise we fade it
						$tooltip.css('left',left + 'px').show();
								left		: left + 'px',
								opacity		: 1
				function hideTooltip(){
					//hide / fade out the tooltip
								opacity		: 0
				function showImage(e){
					var $link				= $(this),
						idx					= $link.index(),
						$image				= $link.find('a').attr('href'),
						$currentImage 		= $ps_image_wrapper.find('img'),
						currentImageWidth	= $currentImage.width();
					//if we click the current one return
					if(current == idx) return false;
					//add class selected to the current page / dot
					//the new image element
					var $newImage = $('<img/>').css('left',currentImageWidth + 'px')
					//if the wrapper has more than one image, remove oldest
					if($ps_image_wrapper.children().length > 1)
					//prepend the new image
					//the new image width. 
					//This will be the new width of the ps_image_wrapper
					var newImageWidth	= $newImage.width();
					//check animation direction
					if(current > idx){
						$newImage.css('left',-newImageWidth + 'px');
						currentImageWidth = -newImageWidth;
					current = idx;
					//animate the new width of the ps_image_wrapper 
					//(same like new image width)
					    width	: newImageWidth + 'px'
					//animate the new image in
					    left	: '0px'
					//animate the old image out
					    left	: -currentImageWidth + 'px'
				function nextImage(){
					if(current < total_images){
				function prevImage(){
					if(current > 0){
<div style="text-align:center;clear:both">

大牛,别默默的看了,快登录帮我点评一下吧!:)      登录 | 注册

热门标签: 图片拖动 图片放大镜 图片叠加 图片翻转旋转 图片延迟加载 图片淡出淡进 图片全屏 图片头像上传 二维码 滚动切换 滑动选项卡切换 图片广告 图片放大缩小 html5图片动画 带缩略图的幻灯片 地图 flash焦点图 图片滚动 图片滑动 图片切换 图片收缩展开 旋转木马 图片轮播 自动滚动图片轮播 图标导航菜单 选项卡切换 滑动手风琴 背景切换 滑动星星打分 手风琴 切换按钮 form表单 图表 焦点图幻灯片 图片 头像截图 其他更多 鼠标悬停 图片相册 图片切换 图片轮播 按钮控制