实战编写jq插件轮播图

<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<style>
	*{padding: 0px;margin: 0px;list-style: none;border: none;vertical-align: middle;}
	.utl li img{float: left;}
	.utl{width: 2800px;height: 250px;position: absolute;left: 0;top: 0;}	
	.umhext{overflow: hidden;width: 700px;height:250px;margin: 50px auto; position: relative;}	
	.bordernone{position: absolute;bottom: 10px;left: 50%;}
	.bordernone i{border: 2px solid #000000;width: 15px;height: 15px;display: inline-block;border-radius: 50%;cursor: pointer;z-index: 1;margin-left: 5px;}
	.bordernone i.auctiy{
		border: 2px solid red;
		
	}
	</style>
	<script src="http://code.jquery.com/jquery-2.0.0.js"></script>
	<body>
		<div class="umhext">
			<ul class="utl">
				<li><img src="1.png"/></li>
				<li><img src="2.png"/></li>
				<li><img src="1.png"/></li>
				<li><img src="2.png"/></li>
			</ul>
			<span class="bordernone"></span>
		</div>
		
		<script>
			(function($){
				// 初始化数据
				var CarouselRest = {
					auctiy:"auctiy",			//标签
					iI:"<i></i>",				//标签
					i:"i",						//类
					utl:".utl",					//标签
					bordernone:".bordernone",	//标签
					timer:1000,					//时间
					widthUmhext:700,			//img宽度
					widthUtl:2800,				//总宽度
					widthBordernone:80,			//iI总宽度
					height:250,					//img高度
					findLi:"li",				//标签	
					Fn:"Function",				//是否为函数
					fag:true					//是否开启定时器true开启 false关闭
				}	
				// 建立数据对象
				$.fn.Carousel = function(pm){
					// 如果参数就重新赋值否则就是默认
					var options = $.extend(true, CarouselRest, pm);
					
					var _self = $(this);
					//初始化索引
					var index = 0;
					
					return _self.each(function(){
						
						var len = _self.find(CarouselRest.findLi);
						
						//计算出所有的小圆圈
						for (var i = 0 ; i<len.length ; i++) {
							
							_self.find(CarouselRest.bordernone).append(CarouselRest.iI);
							
						}
						
						_self.find(CarouselRest.i).eq(0).addClass(CarouselRest.auctiy);
						
						//小圆圈居中
						_self.find(CarouselRest.bordernone).css({
							"left":"50%",
							"marginLeft":-CarouselRest.widthBordernone/2
						})
						
						
						
						//小圆圈事件操作
						_self.find(CarouselRest.i).on("click",function(){
							index = $(this).index();
							
							view(index);
							
						})
						
						
						//图片自动事件
						function auto(){
							index++;
							if(index>=len.length){
								index = 0;
							}
							
							view(index);
							
						}
						
						//在次进行封装
						function view(index){
							_self.find(CarouselRest.i).eq(index).addClass(CarouselRest.auctiy)
							.siblings(CarouselRest.i)
							.removeClass(CarouselRest.auctiy);
							
							
							_self.find(CarouselRest.utl).stop().animate({
								left:-CarouselRest.widthUmhext*index
							},230)
						}
						
						
						//开启定时器
						var stop=null
						if(CarouselRest.fag){
							stop = setInterval(auto,CarouselRest.timer);
							
							_self.hover(function(){
								clearTimeout(stop)								
							},function(){
								stop = setInterval(auto,CarouselRest.timer);
							})
						}
						
					})					
					
				}
				
			})(jQuery)
			
			$(".umhext").Carousel({
					auctiy:"auctiy",			//类
					iI:"<i></i>",				//标签
					i:"i",						//类
					utl:".utl",					//标签
					bordernone:".bordernone",	//类
					timer:1500,					//时间
					widthUmhext:700,			//img宽度
					widthUtl:2800,				//总宽度
					widthBordernone:80,			//iI总宽度
					height:250,					//img高度
					findLi:"li",				//标签	
					Fn:"Function",				//是否为函数
					fag:true					//是否开启定时器true开启 false关闭
			});
		</script>
		
	</body>
</html>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值