scrollimg.js

引用scrollimg.js

(function(win, doc, $) {
	var scrollImg = {
		
		fxcurr:function(){
			if(!_this.def){
					this.lfclick.find("b").addClass("curr");
				}else{
					this.lfclick.find("b").removeClass("curr");
				}
			if(_this.def==-(_this.clonum-1)){
					this.rfclick.find("b").addClass("curr");
				}else{
					this.rfclick.find("b").removeClass("curr");
				}	
				_this.scrollele.stop().animate({left:_this.width*_this.slen*_this.def},_this.speed,_this.easing);
		},
		lbind:function(){
			this.lfclick.click(function(){
				_this.def=_this.def++>=0?0:_this.def;
				_this.fxcurr();
				
			})
		},
		rbind:function(){
			this.rfclick.click(function(){
				_this.def=_this.def--<=-(_this.clonum-1)?-(_this.clonum-1):_this.def;
				_this.fxcurr();
			})
		},

		init: function(obj) {
			
			_this=this;
			
			this.wrap = $(obj.wrap);

			this.speed = obj.speed || 1000;
			
			this.lfclick=$(obj.leftclick);
			
			this.rfclick=$(obj.rightclick);
			
			this.scrollele=$(obj.scrollele);
			
			this.curr = obj.curr || "curr";
			
			this.len=this.scrollele.children().length;
			
			this.slen=obj.slen||4;
			
			this.clonum=Math.ceil(this.len/this.slen);
			
			this.def=0;
			
			this.width = this.scrollele.children().eq(0).outerWidth(true);
			
			this.easing = obj.easing || null;
			
			this.lfclick.find("b").addClass("curr");
			
			if(this.clonum<2)
				this.rfclick.find("b").addClass("curr");
				
			this.lbind();
			this.rbind();
			
			
		}
	};
	win.scrollImg = scrollImg;
})(window, document, jQuery);

添加方法:

$(function(){
scrollImg.init({
	wrap:".scrollwrap",
	leftclick:".coll-left",
	rightclick:".coll-right",
	scrollele:".scrollwrap ul"
		});
	})

html页面

<div class="collection-list clearfix">
	<span class="coll-left"><b class="mico m-left"></b></span>
	<div class="scrollwrap">
		<ul>
			<li>
				<a href="#"><img src="images/pro.jpg" /></a>
				<p>¥151</p>
			</li>
			<li>
				<a href="#"><img src="images/pro.jpg" /></a>
				<p>¥152</p>
			</li>
	                          <li>
				<a href="#"><img src="images/pro.jpg" /></a>
				<p>¥152</p>
			</li>
			<li>
				<a href="#"><img src="images/pro.jpg" /></a>
				<p>¥152</p>
			</li>
	                          <li>
				<a href="#"><img src="images/pro.jpg" /></a>
				<p>¥152</p>
			</li>
		</ul>
	</div>
	<span class="coll-right textR"><b class="mico m-right"></b></span>
</div>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值