jQuery实现图片轮播效果(仿QQ商城首页、天猫首页)



图片轮播是网站中的常用功能,用于在有限的网页空间内展示一组产品图片或者照片,同时还有非常吸引人的动画效果。相信很多同学都在各种类型的网站上看过花样百出的轮播效果图,不少同学也想尝试下自己做出来一个,但网上的代码纰漏百出,不能学以致用,这里我将给大家介绍两种方式的图片轮播实现供大家参考。


实现一

QQ商城轮播效果图

天猫商城轮播效果图


1.制作界面

  1.  <div class="wrapper">  
  2.     <h1>仿2012QQ商城jQuery轮播图效果</h1>  
  3.     <div id="focus">  
  4.         <ul>  
  5.             <li><a href="#"><img src="img/01.jpg" alt="" /></a></li>  
  6.             <li><a href="#"><img src="img/02.jpg" alt="" /></a></li>  
  7.             <li><a href="#"><img src="img/03.jpg" alt="" /></a></li>  
  8.             <li><a href="#"><img src="img/04.jpg" alt="" /></a></li>  
  9.         </ul>  
  10.     </div>  
  11. </div>  
 <div class="wrapper">
	<h1>仿2012QQ商城jQuery轮播图效果</h1>
	<div id="focus">
		<ul>
			<li><a href="#"><img src="img/01.jpg" alt="" /></a></li>
			<li><a href="#"><img src="img/02.jpg" alt="" /></a></li>
			<li><a href="#"><img src="img/03.jpg" alt="" /></a></li>
			<li><a href="#"><img src="img/04.jpg" alt="" /></a></li>
		</ul>
	</div>
</div>

这里我们着重关注id为focus的div,里面我们放了<ul><li></li></ul>,首先我们要做的就是把所有轮播图片编排进去,其次才是对其操作。

1.1统一设置一个样式

  1. * {  
  2.     margin:0;   
  3.     padding:0;  
  4. }  
  5. body {  
  6.     font-size:12px;  
  7.     color:#222;   
  8.     font-family:Verdana,Arial,Helvetica,sans-serif;   
  9.     background:#f0f0f0;  
  10.     }  
  11. ul,li {  
  12.     list-style:none;  
  13. }  
  14. .wrapper {  
  15.     width:800px;   
  16.     margin:0 auto;   
  17.     padding-bottom:50px;  
  18. }  
  19. h1 {  
  20.     height:50px;   
  21.     line-height:50px;   
  22.     font-size:22px;   
  23.     font-weight:normal;   
  24.     font-family:"Microsoft YaHei",SimHei;  
  25. }  
* {
	margin:0; 
	padding:0;
}
body {
	font-size:12px;
	color:#222; 
	font-family:Verdana,Arial,Helvetica,sans-serif; 
	background:#f0f0f0;
	}
ul,li {
	list-style:none;
}
.wrapper {
	width:800px; 
	margin:0 auto; 
	padding-bottom:50px;
}
h1 {
	height:50px; 
	line-height:50px; 
	font-size:22px; 
	font-weight:normal; 
	font-family:"Microsoft YaHei",SimHei;
}

1.2给轮播图设置样式

  1. #focus {  
  2.     height:280px;   
  3.     width:800px;  
  4.     overflow:hidden;  
  5.     position:relative;  
  6. }  
  7. #focus ul {  
  8.     position:absolute;  
  9. }  
  10. #focus ul li {  
  11.     float:left;   
  12.     width:800px;   
  13.     height:280px;   
  14.     background:#000;  
  15. }  
#focus {
	height:280px; 
	width:800px;
	overflow:hidden;
	position:relative;
}
#focus ul {
	position:absolute;
}
#focus ul li {
	float:left; 
	width:800px; 
	height:280px; 
	background:#000;
}

由于图片的高宽分别是280px、800px,这里我们给div设置这个高宽应该很好理解,overflow:hidden;也好理解li经过左浮动以后长度已经远远超出div的width值,需要把多出的部分隐藏。

1.3给轮播图下方的半透明横幅设置样式,这里提供手动鼠标移动切换图片的功能

  1. #focus div.btn {  
  2.     position:absolute;   
  3.     width:800px;   
  4.     height:10px;   
  5.     padding:5px 10px;  
  6.     right:0;   
  7.     bottom:0;   
  8.     text-align:right;  
  9.     background:#000;  
  10.     opacity:0.5;  
  11.     filter:alpha(opacity=50);  
  12. }  
  13. #focus div.btn span {  
  14.     display:inline-block;   
  15.     width:25px;   
  16.     height:10px;   
  17.     margin-left:5px;   
  18.     cursor:pointer;   
  19.     background:#fff;  
  20.     border:1px solid #A020F0;  
  21. }  
#focus div.btn {
	position:absolute; 
	width:800px; 
	height:10px; 
	padding:5px 10px;
	right:0; 
	bottom:0; 
	text-align:right;
	background:#000;
 	opacity:0.5;
	filter:alpha(opacity=50);
}
#focus div.btn span {
	display:inline-block; 
	width:25px; 
	height:10px; 
	margin-left:5px; 
	cursor:pointer; 
	background:#fff;
	border:1px solid #A020F0;
}
div.btn为下方横幅,为半透明;div.btn span为小方框。

1.4点击图片左半部分、右半部分出现的箭头指示,切换上下张图片的效果样式


  1. #focus div.preNext {  
  2.     width:45px;   
  3.     height:100px;   
  4.     position:absolute;   
  5.     top:90px;   
  6.     background-image:url(../img/sprite.png);   
  7.     background-repeat:no-repeat;  
  8.     opacity:0;  
  9.     filter:alpha(opacity=0);  
  10.     cursor:pointer;  
  11. }  
  12. #focus div.pre {  
  13.     left:0;  
  14.     background-position:left top;  
  15. }  
  16. #focus div.next {  
  17.     right:0;   
  18.     background-position:right top;  
  19. }  
  20. #focus span.hidden {  
  21.     display:block;  
  22.     width:400px;  
  23.     height:260px;  
  24.     background:#000;  
  25.     opacity:0;  
  26.     filter:alpha(opacity=0);  
  27.     position:absolute;  
  28.     cursor:pointer;  
  29. }  
  30. #focus span.left {  
  31.     top:0;  
  32.     left:0;  
  33. }  
  34. #focus span.right {  
  35.     top:0;  
  36.     right:0;  
  37. }  
#focus div.preNext {
	width:45px; 
	height:100px; 
	position:absolute; 
	top:90px; 
	background-image:url(../img/sprite.png); 
	background-repeat:no-repeat;
	opacity:0;
	filter:alpha(opacity=0);
	cursor:pointer;
}
#focus div.pre {
	left:0;
	background-position:left top;
}
#focus div.next {
	right:0; 
	background-position:right top;
}
#focus span.hidden {
	display:block;
	width:400px;
	height:260px;
	background:#000;
	opacity:0;
	filter:alpha(opacity=0);
	position:absolute;
	cursor:pointer;
}
#focus span.left {
	top:0;
	left:0;
}
#focus span.right {
	top:0;
	right:0;
}

span.hidden这里虽然我们定义了,但是只是为了把图片一分为2的效果,事实上我们也是把它设为全透明的,界面上根本看不到任何效果

div.preNext 设置了箭头指向,然后再通过图片定位分离出来


2、制作动画效果

由于代码中我都有相关的注释,这里就不再重复的累赘,有不明白的地方可以评论或留言。再多说一句,由于图片轮播效果用到了大量的jquery事件、动画,以及css稍微深一点的知识,如果看起本代码还是费力的同学可以适当的重温下基础。

[javascript] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. $(function() {  
  2.     var sWidth = $("#focus").width(); //获取焦点图的宽度(显示面积)  
  3.     var len = $("#focus ul li").length; //获取焦点图个数  
  4.     var index = 0;  
  5.     var picTimer;  
  6.       
  7.     //以下代码添加数字按钮和按钮后的半透明条,还有上一页、下一页两个按钮  
  8.     var btn = "<div class='btn'>";  
  9.     for(var i=0; i < len; i++) {btn += "<span></span>";}  
  10.     btn += "</div>";  
  11.     btn +="<div class='preNext pre'></div>"+"<div class='preNext next'></div>"+  
  12.               "<span class='hidden left'></span>"+"<span class='hidden right'></span>";  
  13.     $("#focus").append(btn);  
  14.       
  15.       
  16.     //为小按钮添加鼠标滑入事件,以显示相应的内容  
  17.     $("#focus div.btn span").css("opacity",0.4).mouseenter(function() {  
  18.         index = $("#focus div.btn span").index(this);  
  19.         showPics(index);  
  20.     });  
  21.       
  22.     //图片鼠标划过  
  23.     $('#focus span.left').hover(function(){  
  24.         $('#focus div.pre').animate({opacity:'0.5'},500);  
  25.     },function(){  
  26.         $('#focus div.pre').animate({opacity:'0'},500);  
  27.     });  
  28.     $('#focus span.right').hover(function(){  
  29.         $('#focus div.next').animate({opacity:'0.5'},500);  
  30.     },function(){  
  31.         $('#focus div.next').animate({opacity:'0'},500);  
  32.     });  
  33.       
  34.     //上一页按钮  
  35.     $("#focus span.left").click(function() {  
  36.         if(index == -1) {index = len - 1;}  
  37.         showPics(index);  
  38.         index--;  
  39.     });  
  40.     //下一页按钮  
  41.     $("#focus span.right").click(function() {  
  42.         if(index == len){  
  43.             index = 0;  
  44.             showFirstPic();  
  45.         }else{  
  46.             showPics(index);  
  47.         }  
  48.         index ++;  
  49.     });  
  50.   
  51.     //本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度  
  52.     $("#focus ul").css("width",sWidth * (len+1));  
  53.       
  54.     //鼠标滑上焦点图时停止自动播放,滑出时开始自动播放  
  55.     $("#focus").hover(function() {  
  56.         clearInterval(picTimer);  
  57.     },function() {  
  58.         picTimer = setInterval(function() {  
  59.             if(index == len) { //如果索引值等于li元素个数,说明最后一张图播放完毕,接下来要显示第一张图,即调用showFirPic(),然后将索引值清零  
  60.                 index = 0;  
  61.                 showFirstPic();  
  62.             } else { //如果索引值不等于li元素个数,按普通状态切换,调用showPics()  
  63.                 showPics(index);  
  64.             }  
  65.             index++;  
  66.         },2000); //此2000代表自动播放的间隔,单位:毫秒  
  67.     });  
  68.       
  69.     //显示图片函数,根据接收的index值显示相应的内容  
  70.     function showPics(index) { //普通切换  
  71.         var nowLeft = -index*sWidth; //根据index值计算ul元素的left值  
  72.         $("#focus ul").stop(true,false).animate({"left":nowLeft},500); //通过animate()调整ul元素滚动到计算出的position  
  73.         $("#focus div.btn span").animate({"opacity":"0.4"},300).eq(index).animate({"opacity":"1"},100); //为当前的按钮切换到选中的效果  
  74.     }  
  75.     function showFirstPic() { //最后一张图自动切换到第一张图时专用  
  76.         $("#focus ul").append($("#focus ul li:first").clone());//为了达到从最右边到最左边还是往左移动效果,而不是往右移动  
  77.         var nowLeft = -len*sWidth; //通过li元素个数计算ul元素的left值,也就是最后一个li元素的右边  
  78.         $("#focus ul").stop(true,false).animate({"left":nowLeft},500,function() {  
  79.             //通过callback,在动画结束后把ul元素重新定位到起点,然后删除最后一个复制过去的元素  
  80.             $("#focus ul").css("left","0");  
  81.             $("#focus ul li:last").remove();  
  82.         });   
  83.         $("#focus div.btn span").animate({"opacity":"0.4"},300).eq(index).animate({"opacity":"1"},100); //为当前的按钮切换到选中的效果  
  84.     }  
  85. });  
$(function() {
	var sWidth = $("#focus").width(); //获取焦点图的宽度(显示面积)
	var len = $("#focus ul li").length; //获取焦点图个数
	var index = 0;
	var picTimer;
	
	//以下代码添加数字按钮和按钮后的半透明条,还有上一页、下一页两个按钮
	var btn = "<div class='btn'>";
	for(var i=0; i < len; i++) {btn += "<span></span>";}
	btn += "</div>";
	btn +="<div class='preNext pre'></div>"+"<div class='preNext next'></div>"+
			  "<span class='hidden left'></span>"+"<span class='hidden right'></span>";
	$("#focus").append(btn);
	
	
	//为小按钮添加鼠标滑入事件,以显示相应的内容
	$("#focus div.btn span").css("opacity",0.4).mouseenter(function() {
		index = $("#focus div.btn span").index(this);
		showPics(index);
	});
	
	//图片鼠标划过
	$('#focus span.left').hover(function(){
		$('#focus div.pre').animate({opacity:'0.5'},500);
	},function(){
		$('#focus div.pre').animate({opacity:'0'},500);
	});
	$('#focus span.right').hover(function(){
		$('#focus div.next').animate({opacity:'0.5'},500);
	},function(){
		$('#focus div.next').animate({opacity:'0'},500);
	});
	
	//上一页按钮
	$("#focus span.left").click(function() {
		if(index == -1) {index = len - 1;}
		showPics(index);
		index--;
	});
	//下一页按钮
	$("#focus span.right").click(function() {
		if(index == len){
			index = 0;
			showFirstPic();
		}else{
			showPics(index);
		}
		index ++;
	});

	//本例为左右滚动,即所有li元素都是在同一排向左浮动,所以这里需要计算出外围ul元素的宽度
	$("#focus ul").css("width",sWidth * (len+1));
	
	//鼠标滑上焦点图时停止自动播放,滑出时开始自动播放
	$("#focus").hover(function() {
		clearInterval(picTimer);
	},function() {
		picTimer = setInterval(function() {
			if(index == len) { //如果索引值等于li元素个数,说明最后一张图播放完毕,接下来要显示第一张图,即调用showFirPic(),然后将索引值清零
				index = 0;
				showFirstPic();
			} else { //如果索引值不等于li元素个数,按普通状态切换,调用showPics()
				showPics(index);
			}
			index++;
		},2000); //此2000代表自动播放的间隔,单位:毫秒
	});
	
	//显示图片函数,根据接收的index值显示相应的内容
	function showPics(index) { //普通切换
		var nowLeft = -index*sWidth; //根据index值计算ul元素的left值
		$("#focus ul").stop(true,false).animate({"left":nowLeft},500); //通过animate()调整ul元素滚动到计算出的position
		$("#focus div.btn span").animate({"opacity":"0.4"},300).eq(index).animate({"opacity":"1"},100); //为当前的按钮切换到选中的效果
	}
	function showFirstPic() { //最后一张图自动切换到第一张图时专用
		$("#focus ul").append($("#focus ul li:first").clone());//为了达到从最右边到最左边还是往左移动效果,而不是往右移动
		var nowLeft = -len*sWidth; //通过li元素个数计算ul元素的left值,也就是最后一个li元素的右边
		$("#focus ul").stop(true,false).animate({"left":nowLeft},500,function() {
			//通过callback,在动画结束后把ul元素重新定位到起点,然后删除最后一个复制过去的元素
			$("#focus ul").css("left","0");
			$("#focus ul li:last").remove();
		}); 
		$("#focus div.btn span").animate({"opacity":"0.4"},300).eq(index).animate({"opacity":"1"},100); //为当前的按钮切换到选中的效果
	}
});

 天猫商城图片轮播效果


主要代码是一样的,主要是界面不再是一张图片占用整个板块,而是划分好几块,且鼠标移动到相关小图片块,颜色会变亮。

实现二

页面代码
  1. <!DOCTYPE html>  
  2. <html>  
  3.   <head>  
  4.     <title>banner.html</title>  
  5.       
  6.     <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">  
  7.     <meta http-equiv="description" content="this is my page">  
  8.     <meta http-equiv="content-type" content="text/html; charset=UTF-8">  
  9.       
  10.     <link rel="stylesheet" type="text/css" href="style/banner.css">  
  11.     <script type="text/javascript" src="js/jquery-1.5.2.js"></script>  
  12.     <script type="text/javascript" src="js/banner.js"></script>  
  13.   </head>  
  14.     
  15.   <body>  
  16.         <div id="banner">  
  17.             <img src="img/img1.jpg" alt="轮播器第一张" />  
  18.             <img src="img/img2.jpg" alt="轮播器第二张" />  
  19.             <img src="img/img3.jpg" alt="轮播器第三张" />  
  20.             <img src="img/img4.jpg" alt="轮播器第四张" />  
  21.             <span></span>  
  22.             <strong></strong>  
  23.         </div>  
  24.   </body>  
  25. </html>  
<!DOCTYPE html>
<html>
  <head>
    <title>banner.html</title>
	
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    
    <link rel="stylesheet" type="text/css" href="style/banner.css">
    <script type="text/javascript" src="js/jquery-1.5.2.js"></script>
    <script type="text/javascript" src="js/banner.js"></script>
  </head>
  
  <body>
		<div id="banner">
			<img src="img/img1.jpg" alt="轮播器第一张" />
			<img src="img/img2.jpg" alt="轮播器第二张" />
			<img src="img/img3.jpg" alt="轮播器第三张" />
			<img src="img/img4.jpg" alt="轮播器第四张" />
			<span></span>
			<strong></strong>
		</div>
  </body>
</html>
页面这里我们只在外围定义了一个div,里面的span用于轮播图下方的半透明横幅,strong用于显示图片文字描述


CSS代码
  1. * {  
  2.     margin:0;   
  3.     padding:0;  
  4. }  
  5. ul,li {  
  6.     list-style:none;  
  7. }  
  8. #banner {  
  9.     width:750px;  
  10.     height:280px;  
  11.     margin:50px auto;  
  12.     position:relative;  
  13.     overflow:hidden;  
  14. }  
  15. #banner img {  
  16.     display:block;  
  17.     position:absolute;  
  18.     top:0;  
  19.     left:0;  
  20.     z-index:1  
  21. }  
  22. #banner ul {  
  23.     position:absolute;  
  24.     bottom:0px;  
  25.     right:50px;  
  26.     z-index:4;  
  27. }  
  28. #banner ul li {  
  29.     float:left;  
  30.     padding:0 5px;  
  31.     font-size:16px;  
  32.     color:#999;  
  33.     cursor:pointer;  
  34. }  
  35. #banner span {  
  36.     width:750px;  
  37.     height:25px;  
  38.     position:absolute;  
  39.     top:255px;  
  40.     left:0;  
  41.     background:#333;  
  42.     opacity:0.3;  
  43.     filter:alpha(opacity=30);  
  44.     z-index:3;  
  45. }  
  46. #banner strong {  
  47.     position:absolute;  
  48.     top:260px;  
  49.     left:10px;  
  50.     color:#fff;  
  51.     z-index:4;  
  52. }  
* {
	margin:0; 
	padding:0;
}
ul,li {
	list-style:none;
}
#banner {
	width:750px;
	height:280px;
	margin:50px auto;
	position:relative;
	overflow:hidden;
}
#banner img {
	display:block;
	position:absolute;
	top:0;
	left:0;
	z-index:1
}
#banner ul {
	position:absolute;
	bottom:0px;
	right:50px;
	z-index:4;
}
#banner ul li {
	float:left;
	padding:0 5px;
	font-size:16px;
	color:#999;
	cursor:pointer;
}
#banner span {
	width:750px;
	height:25px;
	position:absolute;
	top:255px;
	left:0;
	background:#333;
	opacity:0.3;
	filter:alpha(opacity=30);
	z-index:3;
}
#banner strong {
	position:absolute;
	top:260px;
	left:10px;
	color:#fff;
	z-index:4;
}
我们给img定义的样式都层叠放在一个位置top: 0, left:0,再轮播的时候让它上下或者左右滑动,注意一下banner的 overflow:hidden; 属性这个样式的同学肯定它的用意,就是隐藏溢出,不能在banner外围看到滑动图片。

这里再提到一点我们给banner的div定义了一个相对定位,所以我们其他元素的定位都以绝对定位相对于banner来讲。

js控制代码
[javascript] view plain copy print ? 在CODE上查看代码片 派生到我的代码片
  1. $(function(){  
  2.           
  3.         //轮播器初始化  
  4.         var len = $("#banner img").length;   
  5.         var ul = "<ul>";  
  6.         for(var i=0; i < len; i++){ul += "<li>●</li>";}  
  7.         ul += "</ul>";  
  8.         $(ul).appendTo($("#banner"));  
  9.         $('#banner img').css("opacity",0).css("filter",'alpha(opacity=' + (0*100) + ')');  
  10.         $('#banner img').eq(0).css("opacity",1).css("filter",'alpha(opacity=' + (1*100) + ')');  
  11.         $('#banner ul li').eq(0).css('color''#333');  
  12.         $('#banner strong').html($('#banner img').eq(0).attr('alt'));  
  13.           
  14.         //轮播器计数器  
  15.         var banner_index = 0;  
  16.         //轮播器的种类  
  17.         var banner_type = 2;        //1表示左右,2表示上下滚动  
  18.         //自动轮播器  
  19.         var banner_timer = setInterval(banner_fn, 4000);  
  20.         //手动轮播器  
  21.         $('#banner ul li').hover(function () {  
  22.             clearInterval(banner_timer);  
  23.             if ($(this).css('color') != 'rgb(51, 51, 51)' && $(this).css('color') != '#333') {  
  24.                 banner(this, banner_index == 0 ? $('#banner ul li').size() - 1 : banner_index - 1);  
  25.             }  
  26.         }, function () {  
  27.             banner_index = $(this).index() + 1;  
  28.             banner_timer = setInterval(banner_fn, 3000);  
  29.         });  
  30.         function banner(obj, prev) {  
  31.             $('#banner ul li').css('color''#999');  
  32.             $(obj).css('color''#333');  
  33.             $('#banner strong').html($('#banner img').eq($(obj).index()).attr('alt'));  
  34.               
  35.             if (banner_type == 1)   
  36.             {  
  37.                 $('#banner img').eq(prev).animate({  
  38.                     opacity : '0',  
  39.                     left:"-900px"  
  40.                 },1500).css('z-index', 1);  
  41.                   
  42.                 $('#banner img').eq($(obj).index()).animate({  
  43.                     opacity : '1',  
  44.                     left:"0"  
  45.                 },1500).css('z-index', 2);  
  46.             }  
  47.             else if (banner_type == 2)   
  48.             {  
  49.                 $('#banner img').eq(prev).animate({  
  50.                     opacity : '0',  
  51.                     top : '150px'  
  52.                 },1500).css('z-index', 1);  
  53.                   
  54.                 $('#banner img').eq($(obj).index()).animate({  
  55.                     opacity : '1',  
  56.                     top : '0'  
  57.                 },1500).css('z-index', 2);  
  58.             }  
  59.         }  
  60.           
  61.         function banner_fn() {  
  62.             if (banner_index >= $('#banner ul li').size())   
  63.                 banner_index = 0;  
  64.             banner($('#banner ul li').eq(banner_index),   
  65.                                                             banner_index == 0 ? $('#banner ul li').size() - 1 : banner_index - 1);  
  66.             banner_index++;  
  67.         }  
  68.           
  69. });  
$(function(){
		
		//轮播器初始化
		var len = $("#banner img").length; 
		var ul = "<ul>";
		for(var i=0; i < len; i++){ul += "<li>●</li>";}
		ul += "</ul>";
		$(ul).appendTo($("#banner"));
		$('#banner img').css("opacity",0).css("filter",'alpha(opacity=' + (0*100) + ')');
		$('#banner img').eq(0).css("opacity",1).css("filter",'alpha(opacity=' + (1*100) + ')');
		$('#banner ul li').eq(0).css('color', '#333');
		$('#banner strong').html($('#banner img').eq(0).attr('alt'));
		
		//轮播器计数器
		var banner_index = 0;
		//轮播器的种类
		var banner_type = 2; 		//1表示左右,2表示上下滚动
		//自动轮播器
		var banner_timer = setInterval(banner_fn, 4000);
		//手动轮播器
		$('#banner ul li').hover(function () {
			clearInterval(banner_timer);
			if ($(this).css('color') != 'rgb(51, 51, 51)' && $(this).css('color') != '#333') {
				banner(this, banner_index == 0 ? $('#banner ul li').size() - 1 : banner_index - 1);
			}
		}, function () {
			banner_index = $(this).index() + 1;
			banner_timer = setInterval(banner_fn, 3000);
		});
		function banner(obj, prev) {
			$('#banner ul li').css('color', '#999');
			$(obj).css('color', '#333');
			$('#banner strong').html($('#banner img').eq($(obj).index()).attr('alt'));
			
			if (banner_type == 1) 
			{
				$('#banner img').eq(prev).animate({
					opacity : '0',
					left:"-900px"
				},1500).css('z-index', 1);
				
				$('#banner img').eq($(obj).index()).animate({
					opacity : '1',
					left:"0"
				},1500).css('z-index', 2);
			}
			else if (banner_type == 2) 
			{
				$('#banner img').eq(prev).animate({
					opacity : '0',
					top : '150px'
				},1500).css('z-index', 1);
				
				$('#banner img').eq($(obj).index()).animate({
					opacity : '1',
					top : '0'
				},1500).css('z-index', 2);
			}
		}
		
		function banner_fn() {
			if (banner_index >= $('#banner ul li').size()) 
				banner_index = 0;
			banner($('#banner ul li').eq(banner_index), 
															banner_index == 0 ? $('#banner ul li').size() - 1 : banner_index - 1);
			banner_index++;
		}
		
});

这段代码其实我们主要应该看banner方法,它的两个参数分别是当前图片对象,上一个图片对象,并操作它的定位以及透明度直至消失。

总结:关于图片轮播,相信它的实现方式肯定不止上述的两个,但总归一点,无论何种方式都需要一定的css功底,以及熟练的js应用能力。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
1. 智慧社区背景与挑战 随着城市化的快速发展,社区面临健康、安全、邻里关系和服务质量等多方面的挑战。华为技术有限公司提出智慧社区解决方案,旨在通过先进的数字化技术应对这些问题,提升城市社区的生活质量。 2. 技术推动智慧社区发展 技术进步,特别是数字化、无线化、移动化和物联化,为城市社区的智慧化提供了可能。这些技术的应用不仅提高了社区的运行效率,也增强了居民的便利性和安全性。 3. 智慧社区的核心价值 智慧社区承载了智慧城市的核心价值,通过全面信息化处理,实现对城市各个方面的数字网络化管理、服务与决策功能,从而提升社会服务效率,整合社会服务资源。 4. 多层次、全方位的智慧社区服务 智慧社区通过构建和谐、温情、平安和健康四大社区模块,满足社区居民的多层次需求。这些服务模块包括社区医疗、安全监控、情感沟通和健康监测等。 5. 智慧社区技术框架 智慧社区技术框架强调统一平台的建设,设立数据中心,构建基础网络,并通过分层建设,实现平台能力及应用的可持续成长和扩展。 6. 感知统一平台与服务方案 感知统一平台是智慧社区的关键组成部分,通过统一的RFID身份识别和信息管理,实现社区服务的智能化和便捷化。同时,提供社区内外监控、紧急救助服务和便民服务等。 7. 健康社区的构建 健康社区模块专注于为居民提供健康管理服务,通过整合医疗资源和居民接入,实现远程医疗、慢性病管理和紧急救助等功能,推动医疗模式从治疗向预防转变。 8. 平安社区的安全保障 平安社区通过闭路电视监控、防盗报警和紧急求助等技术,保障社区居民的人身和财产安全,实现社区环境的实时监控和智能分析。 9. 温情社区的情感沟通 温情社区着重于建立社区居民间的情感联系,通过组织社区活动、一键呼叫服务和互帮互助平台,增强邻里间的交流和互助。 10. 和谐社区的资源整合 和谐社区作为社会资源的整合协调者,通过统一接入和身份识别,实现社区信息和服务的便捷获取,提升居民生活质量,促进社区和谐。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值