码迷,mamicode.com
首页 > 其他好文 > 详细

欢迎使用CSDN-markdown编辑器

时间:2016-05-12 13:46:43      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

引用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>

欢迎使用CSDN-markdown编辑器

标签:

原文地址:http://blog.csdn.net/sinrryzhang/article/details/51365230

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!